The Math Forum

Search All of the Math Forum:

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

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

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

Advanced Search

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

Posts: 9,822
Registered: 7/26/08
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:

>> s(1)

ans =

f: 1

>> s(2)

ans =

f: 2

>> s(1,1:2).f

ans =


ans =


>> values = getfield(s,{1,[1 2]}, 'f')

values =


>> [v1 v2] = getfield(s,{1,[1 2]}, 'f')
Error using getfield
Too many output arguments.

% MATLAB 2012A

% Bruno

Date Subject Author
Read getfield
Bruno Luong
Read Re: getfield
Read Re: getfield

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.