1、平面画图(plot)
>>x = [0:0.01:10];
>>y = cos(x);
>>plot(x, y), grid on %画网格
>>xlabel('x'),ylabel('cos(x)'), title(‘三角函数’); %横坐标,纵坐标及图的名称
>>axis([0 8 -1 1]); %横、纵坐标的显示范围
颜色 | 说明符 |
---|---|
白色 | w |
黑色 | k |
蓝色 | b |
红色 | r |
青色 | c |
绿色 | g |
洋红 | m |
蓝色 | y |
2、子图(subplot)
>>x = [0:0.01:5];
>>y = exp(-1.2*x).*sin(20*x);
>>subplot(1,2,1)
>>plot(x,y),xlabel('x'),ylabel('exp(-1.2x)*sin(20x)'),axis([0 5 -1 1]);
>>y = exp(-2*x).*sin(20*x);
>>subplot(1,2,2)
>>plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(20x)'),axis([0 5 -1 1])
3、极坐标(polar)
>>a = 2;
>>theta = [0:pi/90:2*pi];
>>r = a*theta;
>>polar(theta,r), title('阿基米德螺线')
4、对数(loglog)
>>RC = 0.25;
>>s = [1:100]*i;
>>F = abs(1./(1+RC*s));
>>loglog(imag(s),F),xlabel('频率(rad/s)'),ylabel('输出/输入比'),title('频率响应')
5、针状图(stem)
>>t = [0: 5: 200];
>>f = exp(-0.01*t).*sin(t/4);
>>stem(t,f),xlabel('时间(秒)'),ylabel('弹簧响应')
6、等高线(contour)
>>[x,y] = meshgrid(-5:0.1:5, -3:0.1:3);
>>z = x.^2 + y.^2;
>>contour(x,y,z)
>>[C,h] = contour(x,y,z);
>>set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2) %添加标签
7、三维图像(mesh)
>>[x,y] = meshgrid(-2*pi:0.1:2*pi);
>>z = cos(x).*sin(y);
>>mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z')
8、其他命令
x =linspace(a,b,n) %将x设置为分布在[a b],均匀分为n个点
hold on %在同一幅图上继续画
semilogx(x,y) %x 轴使用对数值,y 轴仍然用直接值
semilogy(x,y) %y 轴使用对数值,x 使用直接值
meshgrid %产生矩阵元素
contour3 %三维等高线