Matlab画图小窍门精品资料.doc





《Matlab画图小窍门精品资料.doc》由会员分享,可在线阅读,更多相关《Matlab画图小窍门精品资料.doc(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Matlab图形处理一、二维曲线的绘制语法:plot(x) %绘制以x轴为纵坐标二维曲线 plot(x,y) %绘制以x轴为横坐标、y为纵坐标的二维曲线1、用plot(x)绘图x1=1 2 3; %横坐标根据向量元素序号从1开始的向量plot(x1) x2=0 1 0plot(x2) x2 = 0 1 0 2、用plot(x,y)绘图x1=0:0.1:2*pi;y1=sin(x1);plot(x1,y1) x2=0 1 1 2 2 3;y2=1 1 0 0 1 1;plot(x2,y2)axis(0 4 0 2) 3、矩阵绘图x1=1 2 3;4 5 6 %以矩阵的每一列作图,横坐标为向量1:
2、2plot(x1) x1 = 1 2 3 4 5 6 x2=fix(randn(4,3)*2)plot(x2) x2 = -1 2 0 4 0 -2 0 0 1 0 -1 3 X=-1 2 3Y=1 2 3;4 5 6plot(X,Y) %X是向量,其长度与Y的列数相同,X与Y的每一行绘一曲线X = -1 2 3Y = 1 2 3 4 5 6 X1=1 2 3Y1=1 2;3 4;5 6plot(X1,Y1) %X1的长度与Y1的行数相同,X1与Y1的每一列绘一图X1 = 1 2 3Y1 = 1 2 3 4 5 6 X2=1 0;0 -1;1 2Y2=1 2;3 4;5 6plot(X2,Y2
3、) %如果X2,Y2均是矩阵,则它们的大小必须相同,矩阵X2的每一列和Y2的每一列绘一曲线X2 = 1 0 0 -1 1 2Y2 = 1 2 3 4 5 6 4、复向量绘图Z2=X2+i*Y2plot(Z2) %与plot(real(Z2),imag(Z2)相同Z2 = 1.0000 + 1.0000i 0 + 2.0000i 0 + 3.0000i -1.0000 + 4.0000i 1.0000 + 5.0000i 2.0000 + 6.0000i 5、用plot(x1,y1,x2,y2,.)绘制多条曲线x=0:0.1:2*pi;plot(x,sin(x),x,cos(x),x,sin(2
4、*x) 6、指定图形窗口语法:figure(n) % 指定第n个窗口,窗口名为Figure No.n,而不关闭其它窗口7、同一窗口绘制多个子图语法:subplot(m,n,k) %使mn幅子图中的第k幅成为当前图x=0:0.1:2*pi;subplot(2,2,1)plot(x,sin(x)subplot(2,2,2)plot(x,cos(x)subplot(2,2,3)plot(x,sin(2*x)subplot(2,2,4)plot(x,cos(3*x) 8、曲线的线型、颜色和数据点型(见书本p140表格)语法:plot(x,y,s) %s为类型说明的字符串参数,可以是线型,颜色和数据点型
5、之一或三种组合.clfx=0:0.1:2*pi;plot(x,sin(x),r-.)hold on %使当选前坐标系和图形保留plot(x,cos(x),b:o) 9、文字标注:包括图名(Title)、坐标轴(Lable)、文字注释(Text)和图例(Legend)语法:title(s) %图名 xlabel(s) % x坐标名 ylabel(s) % y坐标名 legend(s,pos) %在指定位置建立图例 legend off %擦除当前图中的图例 text(xt,yt,s) %在图形的(xt,yt)处注释注:pos可取值0 (自动取最佳位置) ,1(右上角,默认位置), 2(左上角),
6、 3(左下角), 4(右下角), -1(图右侧),也可以直接在图中用鼠标将图例拖到满意位置.clear allclfx=0:0.1:2*pi;plot(x,sin(x)hold on plot(x,cos(x),ro) title(y1=sin(x),y2=cos(x)xlabel(x)legend(sin(x),cos(x),4) %在右下角添加图例text(pi,sin(pi),x=pi) 10、交互式图形命令语法:x,y=ginput(n) %用鼠标从图形上获取n个点坐标(x,y) gtext(s) %用鼠标把字符串放置到图形上x=0:0.1:2*pi;plot(x,sin(x)m,n=
7、ginput(2) %获取两点坐标gtext(2pi) %写2pim = 3.1532 6.1855n = -0.0029 -0.0029 二、三维图形的绘制1、三维曲线:语法:plot3(x,y,z,s) %x,y,z是同维向量时,绘制以元素为坐标的三维曲线,当x,y,z是同维的矩阵时,绘制三维曲线的条数等于矩阵的列数。s是指定线型、色彩、数据点型的字符串plot3(x1,y1,z1,s1,x2,y2,s2,.) %绘制多条曲线x=0:0.1:20*pi;plot3(x,sin(x),cos(x) t=(0:1000)/1000*10*pi;x=cos(t);y=sin(t);z=t;plo
8、t3(x,y,z) %绘制螺线 t=linspace(0,20*pi,501);plot3(t.*sin(t),t.*cos(t),t) t=linspace(0,20*pi,501);plot3(t.*sin(t),t.*cos(t),t,t.*sin(t),t.*cos(t),-t) 2、三维曲面语法:X,Y=meshgrid(x,y) %以向量x,y为基准,产生x-y平面的各栅格点坐标值矩阵mesh(z) %以矩阵的行下标作x轴,列下标作y轴,绘制网线图mesh(x,y,z,c) %c是用色矩阵,省略时c=z。绘制网线图surf(z) %绘制曲面图surf(x,y,z,c) %绘制曲面图
9、x=1 2 3 4;y=5 6 7;xx,yy=meshgrid(x,y) %绘网格点xx = 1 2 3 4 1 2 3 4 1 2 3 4yy = 5 5 5 5 6 6 6 6 7 7 7 7 x=linspace(-2,2,30);y=linspace(-2,2,25);xx,yy=meshgrid(x,y);zz=xx.*exp(-xx.2-yy.2);mesh(xx,yy,zz) t=0:0.1:2*pi;x=cos(t);y=sin(t);xx,yy=meshgrid(x,y);zz=xx.2+yy.2;mesh(xx,yy,zz) peaks z = 3*(1-x).2.*ex
10、p(-(x.2) - (y+1).2) . - 10*(x/5 - x.3 - y.5).*exp(-x.2-y.2) . - 1/3*exp(-(x+1).2 - y.2) x,y,z=peaks(50); plot3(x,y,z) r=1;x=-r:0.01:r;y=x;xx,yy=meshgrid(x,y);zz=sqrt(r2-xx.2-yy.2);surf(xx,yy,zz) 3、柱面和球面的绘制语法:x,y,z=cylinder(r,n) %绘制柱面,其中r为一向量,描述母线,表示单位高度里等分刻上定义的半径向量,n为柱面上分格线条数。x,y,z=sphere(n) %绘制球面,n
11、为分格线的条数r=1;cylinder(r,100) r=0:0.1:4;cylinder(r,100) t=2*pi:pi/12:5*pi;r=sin(t)+t; cylinder(r,100) plot(t,r) r=sin(t);cylinder(r,100) t=0:pi/12:3*pi;r=abs(exp(-0.25*t).*sin(t);X,Y,Z=cylinder(r,100);surf(X,Y,Z)colormap(1 0 0) plot(r) clear allt=0:0.1:2*pi;r=t.2;cylinder(r,10) sphere(100) 三、符号函数作图1、单独
12、变量符号函数作图语法:ezplot(Fx,xmin,xmax,ymin,ymax) %在指定x和y范围内,绘制y=f(x)的平面曲线ezplot(Fxy,xmin,xmax,ymin,ymax) %绘制f(x,y)=0的平面曲线ezplot(xt,yt,tmin,tmax) %绘制x=x(t),y=y(t)的平面曲线ezplot3(xt,yt,zt,tmin,tmax) %绘制x=x(t),y=y(t),z=z(t)三维曲线.syms t taoy=2/3*exp(-t/2)*cos(sqrt(3)/2*t);s=subs(int(y,t,0,tao),tao,t);subplot(2,1,1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Matlab画图小窍门 精品资料 Matlab 画图 窍门 精品 资料

限制150内