绘制多个函数图像 ●在同一个绘图窗口绘制多个图像 plot(x1, y1, x2, y2, ... ●也可以同时指定每条曲线的属性 plot(x1, y1, str1, x2, y2, str2,..) ●另一种实现方法: hold on hold on 例:x=0:pi/20:2*pi; plot(x1, y1, str1) 1=sin (x); y2=coS(x); plot(x2, y2, str 2) plot(x, y1, x, y2); hold on; hold off plot(x, y1); plot(x, y2);
11 绘制多个函数图像 plot(x1,y1, x2,y2, ...) ⚫ 另一种实现方法:hold on hold on plot(x1,y1,str1) plot(x2,y2,str2) ... hold off ⚫ 在同一个绘图窗口绘制多个图像 plot(x1,y1,str1, x2,y2,str2, ...) ⚫ 也可以同时指定每条曲线的属性 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); plot(x,y1, x,y2); 例: hold on; plot(x,y1); plot(x,y2);
图例 ●添加图例 legend(str1, str2, .. 例:×=0:pi/2:*pi; y1=sin(x); y2=cos (x) plot (x, y1, bo-,X,y2, ks--; legend sin(x)','cos(x)) ●在任何指定的地方添加文本 text(x,y, str) 将str放到由(x,y)坐标指定的地方 直观方法:直接在绘图窗口进行编辑
12 图例 legend(str1,str2, ...) ⚫ 添加图例 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); plot(x,y1,'bo-', x,y2,'ks--'); legend('sin(x)','cos(x)') 例: ⚫ 在任何指定的地方添加文本 text(x,y,str) ⚫ 将 str 放到由 (x,y) 坐标指定的地方 直观方法:直接在绘图窗口进行编辑
划分绘图窗口 ●划分绘图窗口 subplot (m,n, p) 将一个绘图窗口分割成mxn个子区域,并按行从左至 右依次编号,P表示第P个绘图子区域。 例 X=-pi: pi/20: pi; subplot (2, 2, 1); plot(x, sin(x))3 subplot(2, 2, 2); plot(x, cos(x)); subplot(2, 2, 3) plot(, x. 2; subplot(2, 2, 4); plot(x, exp(x));
13 划分绘图窗口 subplot(m,n,p) ⚫ 将一个绘图窗口分割成 mn 个子区域,并按行 从左至 右 依次编号 ,p 表示第 p 个绘图子区域。 x=-pi:pi/20:pi; subplot(2,2,1); plot(x,sin(x)); subplot(2,2,2); plot(x,cos(x)); subplot(2,2,3); plot(x,x.^2); subplot(2,2,4); plot(x,exp(x)); 例: ⚫ 划分绘图窗口
其他相关命令 ●显示网格 grid on/ grid off ●保留当前绘图窗口中的图像 hold on/ hold of斤f ●新建绘图窗口/选取绘图窗囗 figure(n) ●关闭绘图窗口 close/ close all 14
14 其他相关命令 ⚫ 保留当前绘图窗口中的图像 hold on / hold off ⚫ 新建绘图窗口/选取绘图窗口 figure(n) ⚫ 显示网格 grid on / grid off ⚫ 关闭绘图窗口 close / close all
本讲主要内容 二维平面作图 ●三维曲线 ■三维空间作图 ●空间曲面 符号作图 Matlab绘图过程/原理 15
15 本讲主要内容 ◼ 二维平面作图 ◼ 三维空间作图 ◼ 符号作图 ◼ Matlab 绘图过程/原理 ⚫ 三维曲线 ⚫ 空间曲面