Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,742
Registered: 7/26/08
getfield
Posted: May 26, 2012 6:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
Read getfield
Bruno Luong
5/27/12
Read Re: getfield
Frank
12/25/12
Read Re: getfield
Jason

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.