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: 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 ]
Bruce Elliott

Posts: 127
Registered: 11/9/07
Re: using getfield() with a stuct array
Posted: Jan 18, 2013 4:12 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"James Tursa" wrote in message <kdcd8g$meg$>...
> Are you asking this question because you want to dynamically pick the fieldname at runtime? E.g., myArr.(fieldnamevariable)

Yes, exactly. Ultimately, I want to be able to select elements of a structure array for which the fields have certain values, e.g. myStruct([myStruct.X]>10). I can do that fine at the command line, but I'm creating some tools for other users who are not as familiar with structures, so I want to give them a user-friendly interface that will work with whatever filtering criteria they want to use.

I suppose I could do this with a big switch block with separate (otherwise identical) cases for each field, but that seems kind of cumbersome. Instead, I'm looping through the structure array and testing the field values one at a time. That always feels wrong in Matlab.

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.