




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精品文档应用MATLAB图形函数和绘图实例例1. 输入MATLAB程序如下:x = 0 : 0.2 : 12;y1 = Bessel (1, x );y2 = Bessel ( 2, x );y3 = Bessel ( 3, x );figure ( 1 )subplot ( 2, 2, 1 )h = plot ( x, y1, x, y2, x, y3 );set ( h, LineWidth , 2, LineStyle, -; : , -. ) set ( h, Color , R; G ; B )axis ( 0 12-0.5 1)grid onxlabel ( Time )ylabe
2、l ( Amplitude )legend ( h, First, Second , Third )title ( Bessel Functions)y, ix = min (y1 );text ( x ( ix ), y, First Min rightarrow , HorizontalAlignment , right)Print - depsc -tiff -r200 myplot精品文档应用图形编辑模式 如图所示。按此按钮开始图形编辑模式按这些钮开始增 加字符箭头和线File Edit ViWindow Help改变一个轴的3D视角同学们自己练习各项功能。例2.输入MATLAB程序如
3、下:t = 0 : pi/100 : 2*pi;y = sin (t );Plot ( t, y )grid on继续输入程序如下:y2 = sin (t 0.25 );y3 = sin (t - 0.5 );plot ( t, y, t, y2, t, y3 )可以对线的类型进行定义:t = 0 : pi/100 : 2*pi;y = sin (t );y2 = sin (t 0.25 );y3 = sin (t - 0.5 );plot ( t, y, -, t, y2, -, t, y3,:)练习,对红的颜色进行编辑。例3. 只绘数据点。输入 MATLAB程序如下:x = 0 : pi
4、/ 15 : 4*pi;y = exp ( 2*cos ( x );plot ( x, y, r+ )+,+ ,+101214进一步对图形进行设置:x = 0 : pi /15 : 4*pi;y = exp ( 2*cos ( x );plot ( x, y, -r , x, y, ok )继续对线类型进行设置:x = 0 : pi / 15 : 4*pi;y1 = exp ( 2*cos ( x );y2 = exp ( 2*sin ( x );plot ( x, y1, -*k , x, y2, -.ok )a 5 ID 15202530354045 5D- 4- 6- a练习:把这两条曲
5、线高成不同颜色。例4. 矩阵的线绘。z = peaks; %矩阵为 49M49 Plot ( z )io86420变换方向来绘图:y = 1 : length ( peaks );plot ( peaks, y )2350壮403530251510例5. 用双Y轴绘曲线。t = 0 : pi/20 : 2*pi;y = exp ( sin (t ); plotyy ( t, y, t, y , plot, stem)i亩2.52.50.50.541001 200 2 欧5由000 5 TW初口900把线性轴和对数轴合并绘图。t = 0 : 900; A = 1000; a = 0.005; b
6、 = 0.005;z1 = A * exp ( -a * t );z2 = sin ( b * t );haxes, hlinel, hline2 = plotyy ( t, z1, t, z2, Semilogy, plot);axes ( haxes ( 1 )ylabel ( Semilog Plot)axes ( haxes ( 2 )ylabel ( Linear Plot)set (hline2, LineStyle,-)o一IX不(Dun例6.轴的限制和标记。命令为: axis ( xmin, xmax, ymin, ymax )。 专用标记和标记标号:x = -pi : .1
7、: pi;y = sin (x );plot ( x, y )set ( gca, XTick , -pi : pi/2 : pi )set ( gca, XTickLabel , -pi, -pi/2, 0, pi/2, pi)xlabel ( - pi leg Theta leg pi)ylabel ( sin ( Theta )title ( plot of sin ( Theta )text ( -pi/4, sin ( -pi/4 ), leftarrow sin (-pidiv4 ), HorizontalAlignment , left) set ( findobj ( gca,
8、 Type, line, Color0 0 1 , Color0.5 0 0.5 , Linewidth 2 )plot of sin ( ) l0.6口 E 0.4 0.2 0-0.2 -D.4 -Q.6 -D.6 - I.pi-pi/20pi/2pi- pi Meg Whetm leg pi例7.绘椭圆。t = 0 : pi/20 : 2*pi;plot ( sin ( t ), 2*cos ( t ) grid on当再加入命令axis square后,绘出图形为如果所加入命令 axis equal后,绘出图形为如果所加入命令axis equal tight后,绘出图形为21.6 050
9、0.6-1-1.5,十 t-1维 i 占I a a, * - d1 一-!7.L.& * 例8.显示多个图形。t = 0 : pi/20 : 2*pi;x, y = meshgrid ( t );subplot ( 2, 2, 1 )plot ( sin ( t ), cos ( t ) axis equal subplot ( 2, 2, 2 )z = sin (x ) + cos ( y );plot ( t, z )axis ( 0 2*pi -2 2 )subplot ( 2, 2, 3 )z = sin ( x ).*cos ( y );plot ( t, z )axis ( 0 2
10、*pi -1 1 )subplot ( 2, 2, 4 )z = ( sin ( x ).A2 ) -( cos ( y ).A2);plot ( t, z )axis ( 0 2*pi -1 1 )1(-17-12例9.计算标注文字的位置。t = 0 : 900;hold on;plot ( t, 0.25 * exp ( -0.005 * t );text ( 300, .25 * exp (- 0.005 * 300 ), bulletleftarrow fontname times 0.25 ite 人-0.005 itt at t = 300 ,F ontSize hold off
11、;例10.更详细标注信息。x = linspace ( 0, 2 * pi, 60 );a = sin ( x );b = cos ( x );hold onstem_handles = stem ( x, a + b );plot_handles = plot ( x, a, , x, b, -g,);xlabel ( Time in musecs )ylabel ( Magnitude )title ( Linear Combination of Two Functions ) legend_handles = stem_handles ; plot_handles ;legend ( l
12、egend_handles, a + b, a = sin ( x ), b = cos ( x )Linear Combinatiori of Twd FunctionsC a + ba = sin ( n )b = cos k )例11.更为复杂的标注说明,包括不同统计量。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)b = bar(rand(10,5),stacked); colormap(summer);
13、 hold onx = plot(1:10,5*rand(10,1),marker,square,markersize,12, markeredgecolor,y,markerfacecolor,.6 0 .6, linestyle,-,color,r,linewidth,2); hold offlegend(b,x,Carrots,Peas,Peppers,Green Beans,.Cucumbers,Eggplant) x = 0:.2:12;plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x);legend(First,Second,Third);
14、legend(First,Second,Third,-1)b = bar(rand(10,5),stacked); colormap(summer); hold onx = plot(1:10,5*rand(10,1),marker,square,markersize,12, markeredgecolor,y,markerfacecolor,.6 0 .6,. linestyle,-,color,r,linewidth,2); hold offlegend(b,x,Carrots,Peas,Peppers,Green Beans,.Cucumbers,Eggplant)123456799 1
15、D4.543.532521.510 5D离散数据图形例1.二维的茎图。用函数 y=eYtcosPt。1)连续图形 alpha = .02; beta = .5; t = 0 : 4 : 200 y = exp ( -alpha*t ).*sin ( beta*t ); Plot ( t, y )2)二维的茎图函数为stem ( t, y ),个体具体如下:alpha = .02; beta = .5; t = 0 : 4 : 200 ;y = exp ( -alpha*t ).*sin ( beta*t );stem ( t, y )xlabel ( Time in musecs )ylabe
16、l ( Magnitude )O.B ?0Q-G- T 例11.在Contour绘制的图上标记数值。z = peaks;C , h = contour ( z ,10 );clabel ( C , h )title ( Contour Labeled Using, clabel ( C , h ),) uuFiLuur ilmuhiuu ysiriy*31 C h j45 JO353025201510 55101520253035 4Q 延例12.填充的Contour绘的图z = peaks ;C , h = contourf ( z ,10 );caxis ( -20 20 )title (
17、 Filled Contour Plot Using , Contourf ( z ,10 ) )mitiu uuniuuii liul uing例13.以极坐标形式显示 Contour函数绘图。th , r = meshgrid ( ( 0 : 5 :360 ) * pi/180,0 : .05 :1 );X , Y = pol2cart ( th , r );Z = X + i * Y;f = ( Z .A 4 -1 ) .A ( 1 / 4 );surf (X , Y , abs ( f )hold onsurf ( X , Y , zeros ( size ( X )hold offx
18、label ( Real )ylabel ( Imaginary )zlabel ( Abs ( f )例14.在迪卡尔坐标系中的Contour图。th , r = meshgrid ( ( 0 : 5 :360 ) * pi/180,0 : .05 :1 );X , Y = pol2cart ( th , r );Z = X + i * Y; f = ( Z .人 4-1 ) .A ( 1 / 4 );contour ( X , Y , abs ( f ) , 30 )axis ( -1 1 1 1 )xlabel ( Real , FontSize , 14 )ylabel ( Imagi
19、nary , FontSize, 14 )06060402002-0 4Q60 日-OR -0 4 -0.200.204 口 G 00Real例15.在极轴坐标系中的Contour图。th , r = meshgrid ( ( 0 : 5 :360 ) * pi/180,0 : .05 :1 );X , Y = pol2cart ( th , r );h = polar ( 0 2*pi , 0 1 )delete (h )Z = X + i * Y; f = ( Z .a 4 T ) .a ( 1 / 4 );hold oncontour ( X , Y , abs ( f ) , 30 )
20、270交互式绘图例1.从屏幕上选择绘图的点。axis ( 0 10 0 10 ) hold on xy =;n = 0 ;disp ( Left mouse button picks points .)disp ( Right mouse button picks last points .) but = 1 ;while but = 1xi , yi , but = ginput ( 1 ); plot ( xi , yi , ro ) n= n + 1 ;xy ( :, n ) = xi ; yi ; end t = 1 : n ;ts = 1 : 0.1 :n ;xys = spline
21、 ( t , xy , ts );plot ( xys ( 1,: ) , xys ( 2,: ) , b-) hold offIiiL iIIIi012345679910例2.创建和运行一个 Movie ,图象为最后结果。for k =1 : 16plot ( fft ( eye ( k + 16 )axis equalM ( k ) = getframe ; end movie ( M , 30 )1D.BD.B0.40.20-Q.2-D.JD.E0.0-18-30 丫例3.擦除模式动画。Ay a Ay,其中 A(y)=0-1010dty(2)28-1A = -8/3 0 0 ; 0 T0 10 ; 0 28 T ;y = 35 T0 十;0 0 0 ; 0 0 0 ; h = 0.01 ;p = plot3 ( y ( 1 ) , y ( 2 ) , y ( 3 ) , Square,,EraseMode, background, MarkerSize, 10 ,,MarkerEdgeColor , 1 .7 .7 , MarkerFaceColor , 1 .7 .7 );axis ( 0 50 N5 25 W5
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业用金属材料的性能与选择
- 工业机器人技术的发展与市场前景
- 工业机器人的人机交互设计研究
- 工业自动化生产线监控技术应用
- 工业级数据中心机房的散热系统设计
- 工作、休息两不误的单身公寓布局规划
- 工作中的危机管理与应对
- 工业设计原理与产品设计流程
- 工业节能的途径与方法
- 工业设计创新与产品升级路径
- 2025五年级道德与法治下册期末综合测试卷(含答案)
- 2025至2030中国LNG运输行业市场发展分析及前景预测与战略规划报告
- 主题3 乡土情怀-2025年中考语文现代文阅读主题预测与答题技巧指导(原卷版)
- 湘教版七年级数学下册期末考试卷(含答案与解析)
- DB32T3614-2019 工贸企业安全风险管控基本规范
- 高效规划优化工业园区的基础设施布局
- (王瑞元版本)运动生理学-课件-3-第三章-血液
- 浙江省医疗服务价格项目目录
- 玻璃吊装施工专项施工方案
- 焊接安全知识考核试题及答案
- 2025燃气电厂智能巡检系统技术方案
评论
0/150
提交评论