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: get struct field including empty values
Replies: 12   Last Post: May 13, 2013 9:59 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: get struct field including empty values
Posted: May 13, 2013 9:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"John " <john.wielenbroek@tivaro.nl> wrote in message
news:kmle3f$p5r$1@newscl01ah.mathworks.com...
> dpb <none@non.net> wrote in message <kmjn0s$hkl$1@speranza.aioe.org>...
>> On 5/10/2013 3:47 PM, dpb wrote:
>> ...
>>

>> > allData(allData.correct==1).FieldName
>>
>> Or, of course, if you make the field 'correct' a logical instead of
>> numeric then you can dispense w/ the '==1' part and simply write
>>
>> allData(allData.correct).FieldName
>>
>> --
>>

>
> Hey guys thanks for your responses.
>
> allData(allData.correct==1) does not work because allData.correct returns
> every value as a unique anser, the solution to this is
> allData([allData.correct==1]) but this raises the same problem as stated
> in my first post.
>
> The reason I allow empty values is in this case to differentiate between
> correct responses, incorrect responses, and no responses.


So you're looking for a ternary state and simulating this by using the
binary logical class plus empty. I'd probably switch this around and use 1
for correct answer, -1 for incorrect answer, and 0 for no answer. If you're
worried about an increase in memory consumption, use int8 instead of double.

CORRECT = int8(1);
INCORRECT = int8(-1);
NOANSWER = int8(0);
allData(1).correct = NOANSWER;
allData(1).correct == INCORRECT % false
allData(1).correct == NOANSWER % true

With this coding system, your concatenation-based syntax:

allData([allData.correct]==CORRECT)

just works.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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.