matlab里的subplot,MATLAB中的函数subplot

subplot是MATLAB中的函数

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

subplot是将多个图画到一个平面上的工具。其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一列的,一共m行,如果m=2就是表示2行图。p表示图所在的位置,p=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])

示例3

画上二下一的图

subplot(2,2,1);

。。。。。

subplot(2,2,2);

。。。。。。

subplot(2,2,3:4)

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值