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

dataset arraysubset

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!

Best Answer

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', : );