Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: using getfield() with a stuct array
Posted:
Jan 18, 2013 4:12 PM
|
|
"James Tursa" wrote in message <kdcd8g$meg$1@newscl01ah.mathworks.com>... > > 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.
|
|
|
|