请输入您要查询的百科知识:

 

词条 subplot
释义

函数简介

函数功能

MATLAB中的函数subplot

使用方法: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])

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/21 1:10:28