Home size of struct field from ncinfo
Reply: 2

size of struct field from ncinfo

shamalaia Published in 2017-12-06 20:26:30Z

I want to get the size of a certain field inside a structure.

For example the size of the field Name inside the field Dimensions of the struct obtained from ncinfo:

finfo = ncinfo('example.nc');

>>ans =


ans =


ans =


Just using size causes an obvious error:


Error using size Too many input arguments.

How can I do it in an alternative way?

Also, I would like to save the content of finfo.Dimensions.Name in a separate array or struct. But I get a similar error. For example:


returns the error:

Illegal right hand side in assignment. Too many elements.

gnovice Reply to 2017-12-06 20:48:59Z

Your problem is that the Dimensions field in the structure returned by ncinfo is itself an array of structures, and when you access a field of a structure array it returns a comma-separated list of values, one for each array element. You need to collect these values, for example in a cell array:

nameCell = {finfo.Dimensions.Name};  % Now a 1-by-3 cell array of names

If you just want to know the number of dimensions, you can check the size of the Dimensions field like so:

N = size(finfo.Dimensions);
excaza Reply to 2017-12-06 20:50:10Z

Per the documentation for ncinfo, Dimensions is an array of structures, so you need to be more explicit with what you want to do.

If you want the size of the 'Dimensions' field then that is your query:

S.Dimensions(1).Name = 'x';
S.Dimensions(2).Name = 'y';
S.Dimensions(3).Name = 'z';


Which returns:

ans =

     1     3
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310889 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO