How to create a a scalar NetCDF variable (i.e with no dimensions)?
Show older comments
I need to define a NetCDF variable with a dimension of size zero. The NetCDF function, netcdf.defVar requires a dimid, but it is not possible to define a dimension of length zero, since assigning zero in netcdf.defDim produces an unlimited dimension. Does matlab have any native functions to support zero length variables?
Accepted Answer
More Answers (1)
Jonathan Blythe
on 12 Dec 2011
1 vote
1 Comment
Mary Jo Brodzik
on 16 Jun 2023
I needed to do this same task and it took me a long time to come across this answer. One additional note for others who may also be puzzled: for the CF grid_mapping variable, you only need to define the variable and then add the projection attributes, no need to use 'putVar' to populate it with anything degenerate, e.g.:
varid = netcdf.defVar(ncid, 'crs', 'NC_INT', []);
netcdf.endDef(ncid);
netcdf.putAtt(ncid, varid, 'grid_mapping_name', 'sinusoidal');
% ...then use putAtt for the rest of the 'crs' attributes
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!