MATLAB Examples

This is an example of how to create an line plot with legend in MATLAB®.

Read about the plot function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Load data for the stock indices
load IndexData dates values series

% Plot the stock index values versus time
plot(dates, values)

% Use dateticks for the x axis

% Add title and axis labels
ylabel('Index Value')
title('Relative Daily Index Closings')

% Add a legend in the top, left corner
legend(series, 'Location', 'NorthWest')