来自 ncinfo 的结构字段的大小
size of struct field from ncinfo
我想获取结构中某个字段的大小。
例如从ncinfo
获得的结构的字段Dimensions
内字段Name
的大小:
finfo = ncinfo('example.nc');
finfo.Dimensions.Name
>>ans =
x
ans =
y
ans =
z
仅使用 size
会导致明显的错误:
size(finfo.Dimensions.Name)
Error using size
Too many input arguments.
我怎样才能用其他方式做到这一点?
此外,我想将 finfo.Dimensions.Name
的内容保存在一个单独的数组或结构中。但是我得到了类似的错误。例如:
a.b=finfo.Dimensions.Name
returns错误:
Illegal right hand side in assignment. Too many elements.
您的问题是 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 返回的结构中的 Dimensions
字段:
nameCell = {finfo.Dimensions.Name}; % Now a 1-by-3 cell array of names
如果您只想知道维数,可以像这样检查 Dimensions
字段的大小:
N = size(finfo.Dimensions);
根据 documentation for ncinfo
,Dimensions
是一个 数组 结构,因此您需要更明确地说明您想要做什么。
如果您想要 'Dimensions'
字段的 size
那么这就是您的查询:
S.Dimensions(1).Name = 'x';
S.Dimensions(2).Name = 'y';
S.Dimensions(3).Name = 'z';
size(S.Dimensions)
哪个returns:
ans =
1 3
我想获取结构中某个字段的大小。
例如从ncinfo
获得的结构的字段Dimensions
内字段Name
的大小:
finfo = ncinfo('example.nc');
finfo.Dimensions.Name
>>ans =
x
ans =
y
ans =
z
仅使用 size
会导致明显的错误:
size(finfo.Dimensions.Name)
Error using size Too many input arguments.
我怎样才能用其他方式做到这一点?
此外,我想将 finfo.Dimensions.Name
的内容保存在一个单独的数组或结构中。但是我得到了类似的错误。例如:
a.b=finfo.Dimensions.Name
returns错误:
Illegal right hand side in assignment. Too many elements.
您的问题是 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 返回的结构中的 Dimensions
字段:
nameCell = {finfo.Dimensions.Name}; % Now a 1-by-3 cell array of names
如果您只想知道维数,可以像这样检查 Dimensions
字段的大小:
N = size(finfo.Dimensions);
根据 documentation for ncinfo
,Dimensions
是一个 数组 结构,因此您需要更明确地说明您想要做什么。
如果您想要 'Dimensions'
字段的 size
那么这就是您的查询:
S.Dimensions(1).Name = 'x';
S.Dimensions(2).Name = 'y';
S.Dimensions(3).Name = 'z';
size(S.Dimensions)
哪个returns:
ans =
1 3