subplot

王朝百科·作者佚名  2012-04-27
窄屏简体版  字體: |||超大  

函数简介函数功能MATLAB中的函数subplot[1]

使用方法:subplot(m,n,p)或者subplot(m n p)。

subplot是将多个图画到一个平面上的工具。其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一行的,一共m行,如果第一个数字是2就是表示2行图。p是指你现在要把曲线画到figure中哪个图上,最后一个如果是1表示是从左到右第一个位置。

在matlab的命令窗口中输入doc subplot或者help subplot即可获得该函数的帮助信息。简单的例子把绘图窗口分成两行两列四块区域,然后在每个区域分别作图,基本步骤:

subplot(221); % 2、2、1之间没有空格也可以

在第一块绘图

subplot(222)

在第二块绘图

subplot(223)

在第三块绘图

subplot(224)

在第四块绘图

示例示例1:

在MATLAB的命令窗口依次输入以下命令:(>>不用输入)

>> t=0:0.001:1;

>> y1=sin(10*t);

>> y2=sin(15*t);

>> subplot(211)

>> plot(t,y1)

>> subplot(212)

>> plot(t,y2)

运行结果见右图。也可以将上述命令写成一个程序段:

function subplot_sample1()

close all

figure

grid on

t=0:0.001:1;

y1=sin(10*t);

y2=sin(15*t);

subplot(211)

plot(t,y1)

subplot(212)

plot(t,y2)

示例2:

function subplot_sample1()

close all

figure

grid on

t=0:0.001:1;

subplot(2,2,1)

plot(t,sin(10*t))

subplot(2,2,2)

plot(t,cos(10*t))

subplot(2,2,3)

plot(t,tan(10*t))

subplot(2,2,4)

plot(t,cot(10*t))

示例3:

x1=[1 2 3];

x2=x1;

x3=x2;

x4=x1;

y1=[2 4 6];

y2=2*y1;

y3=3*y1;

y4=4*y1;

subplot(2,2,1)

plot(x1,y1);

axis([0,20,0,20])

subplot(2,2,2)

plot(x2,y2);

axis([0,20,0,20])

subplot(2,2,3)

plot(x3,y3)

axis([0,20,0,20])

subplot(2,2,4)

plot(x4,y4)

axis([0,20,0,20])

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航