当前位置:文档之家› matlab二维平面图形的绘制

matlab二维平面图形的绘制

1、基本图形函数
函数polt是针对向量或矩阵的列来绘制曲线的,其命令格式:(1)plot(x)当x是一向量时,以其元素为纵坐标,其序号为横坐标。

(2)plot(x,y)
(3)plot(x,y1,x,y2,...)绘制多条曲线

>> x=0:pi/10:2*pi;
>> y1=sin(x);
>> y2=cos(x);
>> plot(x,y1,x,y2)
参数选项
y黄 m紫 c青 r红 g绿 b蓝 w白 k黑-实线 :点线 -.点划线 --虚线
.点 o圆 x叉号 +加号 *星号 v下三角 ^上三角
>大于号 <小于号 s正方形 d菱形 h六角形 p五角星

>> plot(x,y1,'r+-',x,y2,'k*:')
2、图形修饰
图形修饰函数:
grid on(/off) 添加或取消网格
xlabel('string')标记横坐标
ylabel('string')标记横坐标
title('string')添加标题
text(x,y,'string')在图形的任意位置增加文本信息gtext('string')利用鼠标添加文本信息
axis([xmin xmax ymin ymax])设置坐标轴的最小最大值例
>> x=0:pi/10:2*pi;
>> y1=sin(x);
>> y2=cos(x);
>> plot(x,y1,x,y2)
>> grid on
>> xlabel('Independent Variable X') >> ylabel('Dedependent Variable Y1&Y2') >> title('sine and cosine curve')
>> text(1.5,0.3,'cos(x)')
>> gtext('sin(x)')
>> axis([0 2*pi -0.9 0.9])
除此之外,在图形窗口中也提供了图形编辑功能,放大、旋转等等3、图形的比较显示
两种方法:
(1)hold on(/off)将新产生的图形曲线叠加到已有图形上去(2)subplot(n,m,k)将图形窗口进行分割

>> x=-pi:pi/10:pi;
>> y1=sin(x);
>> y2=cos(x);
>> y3=x;
>> y4=x.^2;
>> plot(x,y1,x,y2) >> hold on
>> plot(x,y3)
>> plot(x,y4)
>> hold off
>> plot(x,x)

>> x=-pi:pi/10:pi; y1=sin(x);
y2=cos(x);
y3=x;
y4=x.^2;
>> subplot(2,2,1); >> plot(x,y1); >> subplot(2,2,2);
>> plot(x,y2);
>> subplot(2,2,3); >> plot(x,y3); >> subplot(2,2,4); >>
plot(x,y4);。

相关主题