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: subset of dataset
Replies: 3   Last Post: Dec 21, 2012 4:15 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Barry Shaw

Posts: 32
Registered: 2/16/12
subset of dataset
Posted: Dec 20, 2012 10:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi

I use the hospital data already in MATLAB to illustrate:
>> load('hospital')

Simplified version of my problem follows. In reality I may want several criteria, not just two as below.
If I want to pick out those patients Age = 38 I can:
>> subset_Age38 = hospital(hospital.Age == 38,:)

If I want to pick out those patients Age = 39 I can:
>> subset_Age39 = hospital(hospital.Age == 39,:)

If I want to pick out those patients Age = 38 AND 39 I try:
subset_Age3839 = hospital(hospital.Age == [38 39],:)

but get the error
Error using ==
Matrix dimensions must agree.

I can use the following work around, which gives me what I want:
>> ages_to_view = [38 39];
>> [refs] = find(ismember(hospital.Age,ages_to_view));
>> subset_Age3839 = hospital(refs,:)


But is there a way to do this as I initially tried it? I don't want to use a 38 | 40, as I may have an awful lots of values to set as criteria.

Thanks
Barry



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.