Creating a subset of a dataset array based on values in one of the variables

16 visualizzazioni (ultimi 30 giorni)
Suppose I have a dataset array 8 x 3 arranged as such:
Hospital Floor Beds
A R3 10
A T7 10
A Z5 8
B Q1 9
B Q8 23
B G2 13
C I8 13
C D5 15
What I want is a subset of this dataset array in which Hospital Floor is B, as shown below:
Hospital Floor Beds
B Q1 9
B Q8 23
B G2 13
Any ideas? Thanks!

Risposta accettata

owr
owr il 4 Dic 2012
Similar to per isakson's suggestion, but with proper indexing on the "Hospital" column:
>> subset = your_ds_array( strcmp( 'B', your_ds_array.Hospital ), : );
Or, if you want to eliminate the strcmp which can be slow if your array is large and you do alot of these queries, convert the hospital column to a nominal array first:
>> your_ds_array.Hospital = nominal(your_ds_array.Hospital);
>> subset = your_ds_array( your_ds_array.Hospital == 'B', : );

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by