MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Plot Categorical Data


This example shows how to plot data from a categorical array.

Load Sample Data

Load sample data gathered from 100 patients.

load patients

whos

Name Size Bytes Class Attributes

Age 100x1 800 double
Diastolic 100x1 800 double
Gender 100x1 12212 cell
Height 100x1 800 double
LastName 100x1 12416 cell
Location 100x1 15008 cell
SelfAssessedHealthStatus 100x1 12340 cell
Smoker 100x1 100 logical
Systolic 100x1 800 double
Weight 100x1 800 double

Create Categorical Arrays from Cell Arrays of Character Vectors

The workspace variable, Location, is a cell array of character vectors that contains the
three unique medical facilities where patients were observed.

To access and compare data more easily, convert Location to a categorical array.

Location = categorical(Location);

Summarize the categorical array.

summary(Location)

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

39 patients were observed at County General Hospital, 24 at St. Mary's Medical Center,
and 37 at the VA Hospital.

8 Categorical Arrays

Free download pdf