MATLAB Examples

This is an example of how to create a curve with lower and upper bounds in MATLAB®.

For more examples, go to MATLAB Plot Gallery

% Load the data for x, y, and yfit
load fitdata x y yfit

% Create a scatter plot of the original x and y data
scatter(x, y, 'k')

% Plot yfit
line(x, yfit, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 2)

% Plot upper and lower bounds, calculated as 0.3 from yfit
line(x, yfit + 0.3, 'Color', 'r', 'LineStyle', '--', 'LineWidth', 2)
line(x, yfit - 0.3, 'Color', 'r', 'LineStyle', '--', 'LineWidth', 2)

% Add a legend and axis labels
legend('Data', 'Fit', 'Lower/Upper Bounds', 'Location', 'NorthWest')