MATLAB: Dimensions of opened NetCDF files

dimensionsMATLABncloadnetcdf

Hi,
I frequently use NetCDF files to load data in Matlab:
ncload mydata.nc; for a quick open of new files
nc_varget(); to get specific variables
Now, I changed to a new workplace and found here the handling with
ncid = netcdf.open('myfile.nc','nowrite');
varid = netcdf.reqvarid(ncid,'variable');
data = netcdf.getVar(ncid,varid);
This works, but the dimension is changed: While ncload loads the variable correctly as e.g. 12 x 40 x 180 x 90 (as described in the NetCDF file, ncdump),
with netcdf.getVar I get a variable of size 90 x 180 x 40 x12, which is quite inconvenient. Is this a usual behavior of netcdf.xxx or is there something I didn't recognize?
I appreciate any information, Christoph

Best Answer

When you shell out to run ncdump, you are running a C executable that is linked into the netcdf library. Since it is written in C, it used row-major order, so "time_counter" becomes the first dimension listed as it varies the slowest.
MATLAB is column-major order, so "time_counter" gets listed last, since that's where the slowest-varying dimension would be.
So, no, no mistake, it's just fallout from row-major-order vs. column-major-ordering. Also, since you are using NC_VARGET, check the snctools README, there's a discussion of the issue there.