资源预览内容
第1页 / 共34页
第2页 / 共34页
第3页 / 共34页
第4页 / 共34页
第5页 / 共34页
第6页 / 共34页
第7页 / 共34页
第8页 / 共34页
第9页 / 共34页
第10页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
MATLAB程序语言设计应自炉 五邑大学信息学院2007年ziluy163.com ziluyyahoo.com.cnhttp:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛第三讲 MATLAB图形绘制基本技术3.1 MATLAB基本二维图形绘制3.2 plot 命令使用3.3 loglog、semilogx、semilogy、polar3.4 二维曲线的标注3.5 二维图形坐标轴的控制3.6 其他类型的MATLAB二维图形绘制3.7 MATLAB 简单三维图形绘制3.8 例子与习题http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.1 MATLAB 基本二维图形绘制在MATLAB中函数曲线的绘制变得非常得简当,最 基本的函数是 plot 函数,二维图形绘制函数可用 help graph2d列出主要函数,见下表。plot基本的线线性坐标绘图标绘图loglogXY轴轴双Log坐标绘图标绘图semilogxX轴轴Log、Y轴线轴线 性坐标绘图标绘图semilogyX轴线轴线 性、Y轴轴Log坐标绘图标绘图polar极坐标图标图plotyy左右两边边都有坐标轴标轴 的函数曲线绘线绘 制http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.2 plot 命令的使用MATLAB 最基本的图形曲线绘制命令是 plot 函数,而loglog、semilogx和semilogy的用法是一样的,下面详细介绍 plot 的用法。plot 的基本用法有plot(x,y)基本的XY二维图维图 形曲线绘线绘 制 其中 x, y 是x, y两轴轴数据向量plot(x,y,s)s 为为字符串,定义义曲线线的一些属性 ,其他同上一用法plot(x1,y1,s1,x2,y2,s2, )同时绘时绘 制多条曲线线,每条曲线线由 (x, y, s) 定义义http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.2 plot 命令的使用例子:正弦曲线绘制 t=0:0.1:2*pi;y=sin(t);plot(t,y)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.2 plot 命令的使用例子:多条曲线绘制t=0:0.1:2*pi;y=sin(t);cos(t);plot(t,y)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.2 plot 命令的使用例子:两边都有坐标轴曲线绘制 t=0:0.1:2*pi;plotyy(t,sin(t),t,0.01*cos(t)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.2 plot 命令的使用其他绘图选项 (即字符串 s 的使用) s 由下表中一列或两列或三列中属性定义组成,如 s = -.g曲线线线线 型曲线颜线颜 色标记标记 符号选项选项意义义选选 项项意义义选选 项项意义义选选 项项意义义选项选项意义义-实线实线b蓝蓝色c 蓝绿蓝绿 色*星号pentagram五角星虚线线g绿绿色k 黑色.点号o圆圆圈:点线线m 红红紫色r 红红色x叉号square-.点划线线w 白色y 黄色vdiamondnone 无线线用一个 1X3 向量任意指定 r, g, b红绿蓝红绿蓝 三原色hexagram六角星 t=0:0.1:2*pi; y1=sin(t); y2=cos(t); y3=sin(t).*cos(t); plot(t, y1, -, t, y2, :, t, y3, x)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.3 loglog、semilogx、semilogy、polar例子t=0:0.1:6*pi; r=abs(cos(t/3)*100+1; loglog(t,r)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.3 loglog、semilogx、semilogy、polar例子 t=0:0.1:6*pi; r=abs(cos(t/3)*100+1; semilogx(t,r)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.3 loglog、semilogx、semilogy、polar例子 t=0:0.1:6*pi; r=abs(cos(t/3)*100+1; semilogy(t,r)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.3 loglog、semilogx、semilogy、polar例子 t=0:0.1:6*pi; r=cos(t/3)+1/9; polar(t,r)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.4 二维曲线的标注绘制完曲线后,MATLAB还允许用户使用它提供的一些图 形修改函数来进一步修饰画出的图形,标注一些文字信息 。二维图形曲线的标注主要用到下表所示的函数。title(string)标标注图图形标题标题xlabel(string) 标标注X轴标题轴标题ylabel (string)标标注Y轴标题轴标题text标标注文字gtext (string)用鼠标标标标 注文字legend标标注图图例http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.4 二维曲线的标注 t=0:0.1:2*pi; y=sin(t); plot(t, y); title(Sine Wave Curve: Title); xlabel( Time Axis: Xlabel); ylabel( Function Value : Ylabel);例子01234567-1-0.8-0.6-0.4-0.200.20.40.60.81Sine Wave Curve: TitleTime Axis: XlabelFunction Value : Ylabelhttp:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.4 二维曲线的标注text(x, y,string) 在(x, y) 处标注文字 string gtext(string) 用鼠标指定位置标注文字 t=0:0.1:2*pi; y=sin(t); plot(t, y); text( 1, 0, Text annotation ); grid onhttp:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.4 二维曲线的标注legend(string1, string2, string3, ) 将用指定的文字标注在当前图 形上作为图例说明legend( , Pos) 将图例说明标在指定位置: 0 = Automatic “best“ placement (least conflict with data)1 = Upper right-hand corner (default)2 = Upper left-hand corner3 = Lower left-hand corner4 = Lower right-hand corner-1 = To the right of the plot当图例标注已经标注好后,还可用鼠标移动到适当的位置。http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.4 二维曲线的标注x = 0:.2:12;plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x);legend(First,Second,Third);legend(First,Second,Third,-1)例子http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.5 二维图形坐标轴的控制MATLAB还提供有一些函数给用户来控制图形的坐标轴, 主要有下表所示的函数。axis控制坐标轴标轴 尺度zoom放大镜镜grid控制 x, y 轴轴上的网格box坐标轴标轴 外框hold控制是否在当前图图上画曲线线axes在任意位置创创建坐标轴标轴subplot在一幅图图上创创建多幅子图图http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.5 二维图形坐标轴的控制axis 命令的用法见下表axis(xmin, xmax, ymin, ymax 坐标标限设为设为 xmin, xmax, ymin, ymax axis auto自动设动设 置坐标轴标轴 的范围围 axis manual固定坐标轴标轴 范围围,hold on后续图续图 用同样样坐标标范 围围 axis tight坐标标范围设为围设为 数据的上下限 axis ij(x, y)坐标标按矩阵阵下标标方向增长长 axis xy传统传统 的坐标标方向 axis equalx, y 方向同样样尺度标标度 axis image同上,而且坐标标范围设为围设为 数据的上下限 axis square使坐标标外框为为正方形 axis normal使坐标轴设为标轴设为 正常状态态 axis on 或 axis off打开或关闭闭坐标标文字、刻度和背景http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.5 二维图形坐标轴的控制subplot 命令用于在一幅图上创建多幅子图。Subplot(m, n, p) 或 subplot( mnp ) 将图形窗口分解为一个 m X n 的子图 (m X n 个坐标系统),其中 第 p 个坐标系统为当前坐标系统,plot 等命令在该坐标系统上绘曲线。 subplot(211), plot(x, y); subplot(223), stem(x,y); subplot(224), rose(x,y)http:/www.elecfans.com 电子发烧友 http:/bbs.elecfans.com 电子技术论坛3.5 二维图形坐标轴的控制注意下例的复杂分割 subplot(211), plot(x, y); subplot(223), stem(x,y); subplot(224), rose(x,y) subplot(4,4,11), fill(x,y,r);subplot(4,4,12),feather(x,y); subplot(4,4,15),plot(x,y); subplot(4,4,16),stairs(x,y)http:/www
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号