ncwriteschema - assign variables and Dimensions to variables

1 visualización (últimos 30 días)
I really need help with netCDF Schemas.
I would like to export data and therefor create a netCDF-Schema.
This works:
mySchema.Name = '/';
mySchema.Format = 'classic';
mySchema.Dimensions(1).Name = 'rows';
mySchema.Dimensions(1).Length = length([1 2 3 4 5 6 7]');
mySchema.Dimensions(1).Name = 'columns';
mySchema.Dimensions(1).Length = 1;
ncwriteSchema('Testfile',mySchema)
But when trying to add Variables and try to assign Dimensions to the Variables i get an error:
mySchema.Name = '/';
mySchema.Format = 'classic';
mySchema.Dimensions(1).Name = 'rows';
mySchema.Dimensions(1).Length = 7;
mySchema.Dimensions(1).Name = 'columns';
mySchema.Dimensions(1).Length = 1;
mySchema.Variables(1).Name = 'r0';
mySchema.Variables(1).Dimensions = {'rows' 'columns'};
mySchema.Variables(1).Datatype = 'float'
ncwriteschema('Testfile',mySchema)
ERROR:
Attempt to reference field of non-structure array.
Error in internal.matlab.imagesci.nc/writeDimensionSchema (line 1483)
dimNames = {schema.Name};
Error in internal.matlab.imagesci.nc/writeVariableSchema (line 1582)
this.writeDimensionSchema(...
Error in internal.matlab.imagesci.nc/writeGroupSchema (line 1676)
this.writeVariableSchema(schema.Variables, schema.Name);
Error in internal.matlab.imagesci.nc/writeSchema (line 490)
this.writeGroupSchema(schema);
Error in ncwriteschema (line 91)
ncObj.writeSchema(schemastruct);
QUESTION:
I really need help to add the Variables correctly to the netCDF Schema. I hope you guys know an answer.
I think it has something to do with this line:
mySchema.Variables(1).Dimensions = {'rows' 'columns'};
PS: I searched for solutions in MATLAB help and google yet.
  2 comentarios
Clemens
Clemens el 21 de Jun. de 2012
Solution of John works!
Ashish Uthama
Ashish Uthama el 21 de Jun. de 2012
Clemens, you can 'accept' Johns answer if it works for you. That way we know this question is 'solved' :)

Iniciar sesión para comentar.

Respuesta aceptada

John
John el 20 de Jun. de 2012
The specification for the variable dimensions should be the same as in the dimensions themselves, i.e. just listing the dimension names isn't enough. Rewrite as
mySchema.Name = '/';
mySchema.Format = 'classic';
mySchema.Dimensions(1).Name = 'rows';
mySchema.Dimensions(1).Length = 7;
mySchema.Dimensions(2).Name = 'columns';
mySchema.Dimensions(2).Length = 1;
mySchema.Variables(1).Name = 'r0';
mySchema.Variables(1).Dimensions(1) = mySchema.Dimensions(1); % rows
mySchema.Variables(1).Dimensions(2) = mySchema.Dimensions(2); % cols
mySchema.Variables(1).Datatype = 'single';
ncwriteschema(ncfile,mySchema)

Más respuestas (0)

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by