MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Values:
County General Hospital 39
St. Mary s Medical Center 24
VA Hospital 37


The table variables Gender, SelfAssessedHealthStatus, and Location are
categorical arrays. The summary contains the counts of the number of elements in each
category. For example, the summary indicates that 53 of the 100 patients are female and
47 are male.


Select Data Based on Categories


Create a subtable, T1, containing the age, height, and weight of all female patients who
were observed at County General Hospital. You can easily create a logical vector based on
the values in the categorical arrays Gender and Location.


rows = T.Location=='County General Hospital' & T.Gender=='Female';


rows is a 100-by-1 logical vector with logical true ( 1 ) for the table rows where the
gender is female and the location is County General Hospital.


Define the subset of variables.


vars = {'Age','Height','Weight'};


Use parentheses to create the subtable, T1.


T1 = T(rows,vars)


T1=19×3 table
Age Height Weight




Brown 49 64 119
Taylor 31 66 132
Anderson 45 68 128
Lee 44 66 146
Walker 28 65 123
Young 25 63 114
Campbell 37 65 135
Evans 39 62 121
Morris 43 64 135
Rivera 29 63 130
Richardson 30 67 141
Cox 28 66 111
Torres 45 70 137


Convert Text in Table Variables to Categorical
Free download pdf