MATLAB Examples

This is an example of how to create a categorical histogram plot in MATLAB®.

Read about the histogram function in the MATLAB documentation. This function is available in R2017a or newer.

For more examples, go to MATLAB Plot Gallery

% Check version
if verLessThan('matlab','9.2')
    error('heatmap is available in R2017a or newer.')
end

% Load health status data
load patients SelfAssessedHealthStatus

% Convert data to categorical
SelfAssessedHealthStatus = categorical(SelfAssessedHealthStatus,...
    {'Poor' 'Fair' 'Good' 'Excellent'},'Ordinal',true);

% Create histogram
histogram(SelfAssessedHealthStatus)
title('Self Assessed Health Status From 100 Patients')