%sample program to read netcdf and hdf files clear all; %open netcdf file for read access ncid = netcdf.open('example.nc','NC_NOWRITE'); %get info about the file [numdims, numvars, numglobalatts, unlimdimID] = netcdf.inq(ncid); %get information about third variable in the file, display to command %window [varname, xtype, dimids, numatts] = netcdf.inqVar(ncid,2) %get the third variable %first get the variable id varid = netcdf.inqVarID(ncid,varname); %read in the variable third = netcdf.getVar(ncid,varid); %matlab netcdf calls take care of reading in variable as correct type and %doing array permutations for column-major ordering %close netcdf file netcdf.close(ncid); %HDF %get info about hdf file hdf_struct = hdfinfo('example.hdf'); %open example hdf file and read in example sds data = hdfread('example.hdf','Example SDS'); %read in vdata vdata = hdfread('example.hdf','Example Vdata'); %subset sds and vdata data_sub = hdfread('example.hdf','Example SDS','Index',{[], [2 1], []}); vdata_sub = hdfread('example.hdf','Example Vdata','FirstRecord', 2,'NumRecords', 5); %don't need to open or close hdf files in matlab using hdfread %all errors working with netcdf and hdf are captured by matlab in these %function calls and appropriate error messages are printed to the screen %example: specifiy wrong file name for opening ncid = netcdf.open('wrong.nc','NC_NOWRITE');