MATLAB: How to increase the maximum number of dimensions in a netCDF file in MATLAB 7.9 (R2009b)

MATLAB

I have a number of vectors that I want to put in the netCDF file, each with a different length, and I want to define a dimension for each one describing the length of the vector. The NC_MAX_DIMS constant in MATLAB is set to 1024, so I cannot define more than 1024 dimensions for my data.
I want to know if there a way to change the global constant NC_MAX_DIMS.

Best Answer

The ability to increase NC_MAX_DIMS constant is not available in MATLAB 7.9 (R2009b).
Note that you can have multiple variables share one dimension, instead of specifying one dimension per variable. If you know what is the length of the longest vector you would like to put into the netCDF file, you can specify the dimension length to be at least as long as the length of the longest vector, or make a dimension unlimited, as in the example below:
nc = netcdf.create('testfile.nc', netcdf.getConstant('NC_CLOBBER'));
%%define unlimited dimension
unlim_id = netcdf.defDim(nc, 'unlim', netcdf.getConstant('NC_UNLIMITED'));
%%define variables x and y of unlimited dimension
varid1 = netcdf.defVar(nc, 'x', 'double', unlim_id);
varid2 = netcdf.defVar(nc, 'y', 'double', unlim_id);
netcdf.endDef(nc);
%%put data into the variables x and y
netcdf.putVar(nc, varid1,0,3, [1 2 3]);
netcdf.putVar(nc, varid2,0,100,rand(100,1));