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

15 次查看(过去 30 天)
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!

采纳的回答

owr
owr 2012-12-4
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', : );

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by