05基础绘图

plot(x,y) vector pairs(x,y)

plot(y) x = [1...n],n = length(y)

example: plot(cos(0:pi/20:2*pi));

plot(cos(0:pi/20:2*pi));

plot(sin(0:pi/20:2*pi));

matlab画图会进行覆盖,只显示最后一个图像

hold on

plot(cos(0:pi/20:2*pi));

plot(sin(0:pi/20:2*pi));

hold off

同时画出多个图像

plot(x,y,'str') 通过修改str更改plot

hold on

plot(cos(0:pi/20:2*pi),'or');

plot(sin(0:pi/20:2*pi),'xg');

hold off

x = 0:0.5:4*pi;

y = sin(x); h = cos(x); w = 1 ./ (1 + exp(-x));

g = (1 / (2 * pi * 2)^0.5).*exp((-1.*(x - 2 * pi).^2)./(2 * 2^2));

plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,g,'c^-');

legend('sin(x)','cos(x)','Sigmoid','Gauss function'); %标出注解

在一幅图中同时画出四个函数图像

x = 0:0.1:2*pi;y1 = sin(x); y2 = exp(-x);

plot(x,y1,'--*',x,y2,':o');

xlabel('t = 0 to 2 \pi');

ylabel('values of sin(t) and e^{-x}');

title('Function Plots if sin(t) and e^{-x}');

legend('sin(t)','e^{-x}');

增加标题等内容

line函数画出图中那条竖直的线,在画箭头时对实际的x和y坐标进行了归一化,x / 3,y / 4

x = linspace(0,6);

y = sin(x);

plot(x,y);

set(gca,'XLim',[0,2*pi]);

set(gca,'YLim',[-1.2,1.2]);

xlim([0,2*pi]);

ylim([-1.2,1.2]);

set(gcs,'FontSize',25);

x = linspace(0,6);

y = sin(x);

plot(x,y);

h = plot(x,y);

set(gca,'XLim',[0,2*pi]);

set(gca,'YLim',[-1.2,1.2]);

set(h,'LineStyle','-.','LineWidth',7.0,'Color','g');

delete(h);

x = -10:0.1:10;

y1 = x .^2-8;

y2 = exp(x);

figure,plot(x,y1);

figure,plot(x,y2);

这时如果使用gcf指出的figure等是现在的,也就是第二幅图的,会覆盖之前的

figure('Position',[left,bottom,width,height]);

指明figure也就是边框的位置和大小

发布了133 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/sgsyacm/article/details/100521545