MATLAB Examples

This is an example of how to create a stair-step plot in MATLAB®.

Read about the stairs function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Load data on beak length
load beaksData beaks

% Calculate histograms for the beak data
minBeak = min(beaks);
maxBeak = max(beaks);
nbins = minBeak:0.2:maxBeak;
[nB, xB] = hist(beaks, nbins);

% Create a stair plot of beak sizes
stairs(xB, nB/sum(nB), 'b')

% Add title and axis labels
title('Ground finch beak sizes')
xlabel('Beak size in mm')
ylabel('Fraction of birds with beak size')