应用MATLAB图形函数和绘图实例.doc
文本预览下载声明
应用MATLAB图形函数和绘图实例
输入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 on
xlabel ( ‘ Time ’ )
ylabel ( ‘ 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
改变一个轴的3D视角按这些钮开始增加字符箭头和线按此按钮开始图形编辑模式应用图形编辑模式
改变一个轴的3D视角
按这些钮开始增加字符箭头和线
按此按钮开始图形编辑模式
如图所示。
同学们自己练习各项功能。
输入MATLAB程序如下:
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, ‘ : ’ )
练习,对红的颜色进行编辑。
只绘数据点。输入MATLAB程序如下:
x = 0 : pi / 15 : 4*pi;
y = exp ( 2*cos ( x ) );
plot ( x, y, ‘ r+ ’ )
进一步对图形进行设置:
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 ’ )
练习:把这两条曲线高成不同颜色。
矩阵的线绘。
z = peaks; %矩阵为49?49
plot ( z )
变换方向来绘图:
y = 1 : length ( peaks );
plot ( peaks, y )
用双Y轴绘曲线。
t = 0 : pi/20 : 2*pi;
y = exp ( sin ( t ) );
plotyy ( t, y, t, y , ‘plot’, ‘stem’ )
把线性轴和对数轴合并绘图。
t = 0 : 900; A = 1000; a = 0.005; b = 0.005;
z1 = A * exp ( -a * t );
z2 = sin ( b * t );
[ haxes, hline1, hline2 ] = plotyy ( t, z1, t, z2, ‘semilogy’, ‘plot’ );
axes ( haxes ( 1 ) )
ylabel ( ‘Semilog Plot’ )
axes ( haxes ( 2 ) )
ylabel ( ‘Linear Plot’ )
set (hline2, ‘LineStyle’, ‘ -- ’ )
轴的限制和标记。
命令为: axis ( [ xmin, xmax, ymin, ymax ])。专用标记和标记标号:
x = -pi : .1 : pi;
y = sin ( x );
plot ( x, y )
set ( gca, ‘XTick’, -pi : pi/2 : pi )
set ( gca, ‘XTic
显示全部