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: using getfield() with a stuct array
Replies: 3   Last Post: Jan 18, 2013 5:14 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Tursa

Posts: 2,096
Registered: 8/5/09
Re: using getfield() with a stuct array
Posted: Jan 18, 2013 4:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Bruce Elliott" <bruce.elliott@jhuapl.nospam.edu> wrote in message <kdc3h7$d6b$1@newscl01ah.mathworks.com>...
> Is there any way to use getfield() on an array of structure and to get a same-sized array of field values?
>
> In other words, I can do this:
>
> x = [myArr.F];
>
> to get an array with the values in the field F in my stuct array, myArr.
>
> This, however, does not work:
>
> x = getfield(myArr,'F');
>
> (Putting [] around anything on the right-hand-side does not help.)
>
> There's probably a good reason for this, but the documentation suggests that x = getfield(S,'F') is equivalent to x = S.F, so I would have hoped that I could do this.


Are you asking this question because you want to dynamically pick the fieldname at runtime? E.g., myArr.(fieldnamevariable)

James Tursa



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.