ncwriteschema - assign variables and Dimensions to variables

1 次查看(过去 30 天)
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.

采纳的回答

John
John 2012-6-20
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by