|
|
getfield
Posted:
May 26, 2012 6:21 AM
|
|
According to the documentation of getfield
[ value = getfield(struct,{sIndx1,...,sIndxM},'field',{fIndx1,...,fIndxN}) returns the contents of the specified field, equivalent to value = struct(sIndx1,...,sIndxM).field(fIndx1,...,fIndxN). The getfield function supports multiple sets of field and fIndx inputs, and all Indx inputs are optional. If structure struct or any of the fields is a nonscalar structure, and you do not specify an Indx, the getfield function returns the values associated with the first index. If you specify a single colon operator for an fIndx input, enclose it in single quotation marks: ':'. ]
Can someone explains why I can't not get the field of an array:
>> s = struct('f',{1 2})
s =
1x2 struct array with fields: f
>> s(1)
ans =
f: 1
>> s(2)
ans =
f: 2
>> s(1,1:2).f
ans =
1
ans =
2 >> values = getfield(s,{1,[1 2]}, 'f')
values =
1
>> [v1 v2] = getfield(s,{1,[1 2]}, 'f') Error using getfield Too many output arguments. % MATLAB 2012A
% Bruno
|
|