当前位置:文档之家› 第4讲 Matlab语言基础(3)

第4讲 Matlab语言基础(3)


\omega
\zeta \eta \lambda \xi \pi
ω
δ ε λ ξ π
\neq
\leftarrow \rightarrow \uparrow \downarrow

← → ↑ ↓

第5章 MATLAB语言的绘图基础基础
【例5-9】对例5-1的图形进行适当标注。 t=0:pi/100:2*pi; y=sin(3*t); plot(t,y); grid on xlabel('\fontsize{20}\itt\rm/s'); ylabel('\fontsize{20}y=sin(3t)'); title('\fontsize{20}plot of y=sin(3t)');
>> x=[1 2;3 4]; >> y=[5 6;8 12]; >> plot(x,y))
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
1 2 5 6 【例5-3】 x ,y 7 8 ,绘制复数函数z=x+iy的图形。 3 4
第3章 MATLAB的数值运算与符号运算基础
第3章 MATLAB的数值运算与符号运算基础
第3章 MATLAB的数值运算与符号运算基础
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
4. 绘制双坐标图 命令格式:plotyy(x1,y1,x2,y2) 【例5-16】用plotyy命令绘制双坐标图。
第5章 MATLAB语言的绘图基础基础
xlabel('\itt'); ylabel('y'); legend('sin(t)','cos(t)','sin(t)+cos(t)','sin(t)*cos(t)')
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
3. 指定不同图形窗口 命令格式:figure(n) 【例5-15】用figure命令指定不同图形窗口绘制多图。
青色(cyan)
绿色(green) 黑色(black) 紫色(magenta) 红色(red) 白色(white) 黄色(yellow)

左三角形
第5章 MATLAB语言的绘图基础基础
【例5-5】用不同的修饰方式分别绘制y=sinx和y=sinx+cosx的图形。
程序1
>> t=0:pi/20:2*pi; y=sin(t); plot(t,y,'-.or')
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
程序2
>> t=0:pi/20:2*pi; y=sin(t)+cos(t); plot(t,y,‘<')
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
2. 图形坐标轴的属性设置
稀疏模式图
第5章 MATLAB语言的绘图基础基础
【例5-17】对于数组x=y=0:1000,试用对数函数,半对数函数分 别绘制其曲线。
clear x=0:1000; 第5章 y=0:1000; subplot(2,2,1) plot(x,y); title('Plot'); grid on subplot(2,2,2) semilogx(x,y); title('Semilogx'); grid on subplot(2,2,3) semilogy(x,y); title('Semilogy'); grid on subplot(2,2,4) loglog(x,y); title('Loglog'); grid on
t=0:pi/100:2*pi; y1=sin(t); y2=cos(t); y3=sin(t)+cos(t); y4=sin(t).*cos(t);
第5章 MATLAB语言的绘图基础基础
figure(1) plot(t,y1,'r-'); hold on xlabel('\itt'); ylabel('y'); lineobj = findobj('type', 'line'); set(lineobj, 'linewidth', 1.8); figure(2) plot(t,y2,'b:'); hold on xlabel('\itt'); ylabel('y'); lineobj = findobj('type', 'line'); set(lineobj, 'linewidth', 1.8);
>> p=[22 60 88 95 56 23 9 10 14 81 56 23]; >> plot(p)
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
5.1.2 图形的修饰 1. 图形属性设置

线:线型、颜色 点:点的类型、颜色
文字标注
坐标设置 添加特殊字符
第4讲 MATLAB语言基础(3)
第5章 MATLAB语言的绘图基础
第6章 MATLAB的GUI程序设计初步
第5章 MATLAB语言的绘图基础基础
第5章 MATLAB语言的绘图基础基础
二维图形
三维图形
特殊应用图形
符号函数图形
图形修饰
第5章 MATLAB语言的绘图基础基础
5.1 二维图形的绘制
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础

坐标轴背景网格的设置
命令格式:grid on; grid off 【例5-7】为例5-1的图形加上网格线。 >> t=0:pi/100:2*pi; y=sin(3*t); plot(t,y); grid on
第3章 MATLAB的数值运算与符号运算基础
>> >> >> >> x=[1 2;3 4]; y=[5 6;8 12]; z=x+i*y; plot(z)
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
【例5-4】某工厂2000年各月总产值(单位:万元)分别为:22, 60,88,95,56,23,9,10,14,81,56,23,试绘制折线 图以显示该厂一年内总产值的变化情况。
第5章 MATLAB语言的绘图基础基础
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
2. 在同一图形上保持上次图形进行多次叠加 命令格式:hold on/hold off 【例5-13】用hold命令进行多图绘制。
t=0:pi/100:2*pi; y1=sin(t); y2=cos(t); y3=sin(t)+cos(t); y4=sin(t).*cos(t); plot(t,y1,'r-'); hold on plot(t,y2,'b:'); hold on plot(t,y3,'g-.'); hold on grid on plot(t,y4,'y--'); grid on hold off

坐标轴的范围与刻度设置
命令格式:axis([xmin xmax ymin ymax])
【例5-6】比较以下两程序的运行结果。
程序1 >> x=0:0.025:pi/2; plot(x,tan(x),'-bo')
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
程序2 >> x=0:0.025:pi/2; plot(x,tan(x),'-bo') axis([0 pi/2 0 5])
第3章 MATLAB的数值运算与符号运算基础
第5章 MATLAB语言的绘图基础基础
5.1.3 多图绘制函数 1. 在同一窗口绘制多个子图形 命令格式:subplot(m,n,p)
【例5-11】用subplot函数在同一窗口绘制的多个子图。
t=0:pi/100:2*pi; y1=sin(t); y2=cos(t); y3=sin(t)+cos(t); y4=sin(t).*cos(t); subplot(2,2,1) plot(t,y1); xlabel('\itt\rm/s'); ylabel('y_1=sin(t)'); subplot(2,2,2) plot(t,y2); xlabel('\itt\rm/s'); ylabel('y_2=cos(t)'); subplot(2,2,3) plot(t,y3); xlabel('\fontsize{20}\itt\rm/s'); ylabel('\fontsize{20}y_3=sin(t)+cos(t)'); grid on subplot(2,2,4) plot(t,y4); xlabel('\fontsize{20}\itt\rm/s'); ylabel('\fontsize{20}y_4=sin(t)*cos(t)'); grid on
第5章 MATLAB语言的绘图基础基础
相关主题