MATLAB Plot Line Style & Color Guide

In Matlab, you can use the plot function to draw graphs and customize the line style and color. The following is an example code on how to set the line style and color:

x = 0:0.1:10;
y1 = sin(x);
y2 = cos(x);

% 绘制y1并设置线型为红色实线
plot(x, y1, 'r-');
hold on;

% 绘制y2并设置线型为蓝色虚线
plot(x, y2, 'b--');

xlabel('x');
ylabel('y');
legend('sin(x)', 'cos(x)');
title('Sin and Cos functions');

hold off;

In the example above, ‘r-‘ represents a solid red line and ‘b–’ represents a dashed blue line. You can choose different line types and colors as needed to create a graph.

bannerAds