MATLAB Examples

This is an example of how to create an line plot from a function in MATLAB®.

Read about the fplot function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Create a function plot of y = x^3 over the domain of [-2 2].
% Plot with a thick red line.
fplot(@(x) x.^3, [-2 2], 'r', 'LineWidth',2)

% Add labels and title
title('y = x^3')