Why do I receive an error writing data to netCDF variable with the unlimited option in MATLAB 7.8 (R2009a)?

12 visualizaciones (últimos 30 días)
I am trying to write data to a netCDF variable with infinite dimension in MATLAB 7.8 (R2009a). I execute the following code:
nc = netcdf.create('testfile.nc', netcdf.getConstant('NC_CLOBBER'));
%%define unlimited dimension
unlim_id = netcdf.defDim(nc, 'unlim', netcdf.getConstant('NC_UNLIMITED'));
%%define a dimension of length 50
dim_id = netcdf.defDim(nc, 'x', 50);
%%define a variable 'time' of unlimited dimension
t_id = netcdf.defVar(nc, 'time', 'double', unlim_id);
%%define a variable 'z' that has 2 dimensions
z_id = netcdf.defVar(nc, 'z', 'double', [dim_id unlim_id]);
netcdf.endDef(nc);
I now try putting data into variable 'time':
netcdf.putVar(nc, t_id, [1 2 3]);
or when I try putting data into variable 'z':
netcdf.putVar(nc, z_id, rand(30,20));
I get the following error: ERROR: ??? Error using ==> netcdflib The number of input elements does not match the variable size.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 18 de Ag. de 2019
Editada: MathWorks Support Team el 18 de Ag. de 2019
This enhancement has been incorporated in Release 2010a (R2010a). For previous product releases, read below for any possible workarounds:
While using netCDF, when an unlimited dimension is created i.e., a dimension that can grow, the dimension length is set equal to zero by default. While growing this dimension, you need to specify the start and count. Note that if you are writing to a netCDF variable that has been defined as having N dimensions, the start and count arguments must both be N-element vectors:
netcdf.putVar(nc, t_id, 0, 3, [1 2 3]);
netcdf.putVar(nc, z_id, [0 0], [30 20], rand(30,20));

Más respuestas (0)

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by