Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: getfield
Replies: 2   Last Post: Dec 25, 2012 9:30 PM

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,822 Registered: 7/26/08
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

Date Subject Author
5/26/12 Bruno Luong
5/27/12 Frank
12/25/12 Jason