绘制单条曲线
x = 0:pi/100:2*pi; //表示x取0到2*pi之间的值,每个值之间间隔pi/100
y = sin(x);
plot(x,y);
绘制多条曲线
x = linspace(-2*pi, 2*pi);//x取值范围为-2*pi到2*pi
y1 = sin(x);
y2 = cos(x);
figure;
plot(x,y1,x,y2);
从矩阵创建线图
Y = magic(4);
figure;
plot(Y);
magic是一种函数,用于产生魔方矩阵,它的每行、列以及对角线的数之和相等。该和的值为1+2+3+…+n^2的和再除以n,n必须为大于或等于3的整数。
指定线条样式、颜色
x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure;
plot(x,y1,x,y2,'--',x,y3,':');
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure;
plot(x,y1,'g',x,y2,'b--o',x,y3,'c*');
在特定数据点显示标记
x = linspace(0,10);
y = sin(x);
plot(x,y,'-o','MarkerIndices',1:5:length(y));
指定线宽、标记大小和标记颜色
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
figure
plot(x,y,'--gs',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','b',...
'MarkerFaceColor',[0.5,0.5,0.5])
添加标题和轴标签
x = linspace(0,10,150);
y = cos(5*x);
figure
plot(x,y,'Color',[0,0.7,0.9])
title('2-D Line Plot')
xlabel('x')
ylabel('cos(5x)')
绘制持续时间并指定刻度格式
t = 0:seconds(30):minutes(3);
y = rand(1,7);
plot(t,y,'DurationTickFormat','mm:ss')
指定线图的轴
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
p = plot(x,y1,x,y2);
创建后修改行
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
p = plot(x,y1,x,y2);
p(1).LineWidth = 2;
p(2).Marker = '*';
修改前:-
修改后:
画圆
r = 2;
xc = 4;
yc = 3;
theta = linspace(0,2*pi);
x = r*cos(theta) + xc;
y = r*sin(theta) + yc;
plot(x,y)
axis equal
来源:CSDN
作者:yyyyygq
链接:https://blog.csdn.net/y18771025420/article/details/103245614