繪製sin曲線
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y);
設置樣式
- 連續線、點線等
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y,'LineStyle','-.'); % 斷點線
- 線的粗細
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y,'LineWidth',2); %線寬爲2,默認爲0.5
- 線的顏色
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y,'Color','r'); %紅色線
- 數據點樣式
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y,'Marker','s'); %方塊點
設置標題、xlabel、ylabel
x = 0:pi/10:2*pi;
y = sin(x);
plot(x,y);
title('sin demo');
xlabel('x axis');
ylabel('y axis');
在一張圖上繪製多條曲線
繪製兩條曲線
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = cos(x);
figure
plot(x,y1);
hold on
plot(x,y2)
legend('sin','cos')
hold off
一次繪製一個點
x = 0:pi/10:2*pi;
y = sin(x);
figure
for i=1:length(x)
plot(x(i),y(i),'Marker', 's')
hold on
end
hold off
subplot
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = cos(y);
y3 = x;
y4 = x.^2;
y5 = 1./(x+1);
y6 = exp(x);
figure
subplot(2,3,1) %2x3=6張圖,編號從1到6,從上到下,從左到右
plot(x,y1)
subplot(2,3,2)
plot(x,y2)
subplot(2,3,3)
plot(x,y3)
subplot(2,3,4)
plot(x,y4)
subplot(2,3,5)
plot(x,y5)
subplot(2,3,6)
plot(x,y6)