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

14 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

owr
owr el 4 de Dic. de 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', : );

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by