MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
VA_CountyGenIndex is a 100-by-1 logical array containing logical true ( 1 ) for each
element in the categorical array Location that is a member of the category County
General Hospital or VA Hospital. The output, VA_CountyGenIndex contains 76
nonzero elements.

Use the logical vector, VA_CountyGenIndex to select the LastName of the patients
observed at either County General Hospital or VA Hospital.

VA_CountyGenPatients = LastName(VA_CountyGenIndex);

VA_CountyGenPatients is a 76-by-1 cell array of character vectors.

Select Elements in a Particular Category to Plot

Use the summary function to print a summary containing the category names and the
number of elements in each category.

summary(Location)

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

Location is a 100-by-1 categorical array with three categories. County General
Hospital occurs in 39 elements, St. Mary s Medical Center in 24 elements, and
VA Hospital in 37 elements.

Use the summary function to print a summary of Gender.

summary(Gender)

Female 53
Male 47

Gender is a 100-by-1 categorical array with two categories. Female occurs in 53
elements and Male occurs in 47 elements.

Use logical operator == to access the age of only the female patients. Then plot a
histogram of this data.

figure()
histogram(Age(Gender=='Female'))
title('Age of Female Patients')

8 Categorical Arrays

Free download pdf