Select Rows with Logical Indexing
You can index into an array or a table using an array of logical indices. Typically, you use a logical
expression that determines which values in a table variable meet a condition. The result of the
expression is an array of logical indices.
For example, create logical indices matching patients whose age is less than 40.
rows = T.Age < 40
rows = 100x1 logical array
1
0
1
0
0
0
1
0
1
1
⋮
To extract heights for patients whose age is less than 40, index into the Height variable using rows.
There are 56 patients younger than 40.
T.Height(rows)
ans = 56×1
71
64
64
68
66
71
72
65
69
69
⋮
You can index into a table with logical indices. Display the rows of T for the patients who are younger
than 40.
T(rows,:)
ans=56×5 table
Age
Gender
Height
Weight
Smoker
___
__________
______
______
______
Smith
38
{'Male' }
71
176
true
Williams
38
{'Female'}
64
131
false
Miller
33
{'Female'}
64
142
true
Moore
28
{'Male' }
68
183
false
Access Data in Tables
9-39
Précédent

- 383/1450

Suivant