How to write struct dataype into a netCDF using ncwrite?

9 vues (au cours des 30 derniers jours)
PJ
PJ le 27 Mar 2012
Hi, I have a 1000 struct datatype (A) with two attributes (myB and myC): i.e
A(1).myB = [2D matrix]
A(1).myC = [1D array]
.
.
. A(1000).myB = [2D matrix]
A(1000).myC = [1D array]
How do I write this into a netCDF file using MATLAB? (using ncwrite etc)

Réponses (1)

Ashish Uthama
Ashish Uthama le 27 Mar 2012
As of today, MATLAB's netcdf layer does not support user defined data (C structs), variables need to be one of the defined external types.
With NetCDF files, the term 'attribute' usually refers to additional meta data for a variable.
How you write the data to the NetCDF file would largely depend on how you plan to use the data later. Is it to import data to another application? (In which case, the layout will be dictated by that that tools supports). Or is it just for storage? (in which case, mat files would be easier).
One way to look at your data is as if it has two variables, myB and myC with sizes 2Dx1000 (Say 20x30x1000) and 1Dx1000 (say 15x1000) respectively. Use nccreate to create these two variables and ncwrite to write them out. You would also have to name and create each of the dimensions of this variable. Have a look at the second example in ncwrite to get a better idea.
  2 commentaires
PJ
PJ le 27 Mar 2012
My output is quite large i.e. 15GB. Storing these in MAT files is not a big problem, however, 'load' and 'save' from/to MAT files, for very large data is very time consuming. Is there a faster way to access very large dataset?
Ashish Uthama
Ashish Uthama le 28 Mar 2012
PJ, thats a whole new question :)
Format wise, I dont think you get faster than plain binary (fread/fwrite) combo.
There might be other things you can do to speed up the process which rely on your compute hardware (SSD's, RAID, or maybe ramdrives if you have enough memory)

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by