matlab中pause函数怎么用,matlab中pause的用法
MATLAB里的pause
一般是为了动态观察变化过程 pause(a)暂停a秒后执行下一条指令

matlab中,如何控制函数图形描绘的速度?
PAUSE Wait for user response. PAUSE等待用户的相应。
PAUSE(n) pauses for n seconds before continuing, where n can also be a fraction. The resolution(分辨率) of the clock is platform specific. Fractional pauses of 0.01 seconds should be supported on most platforms.
PAUSE(n)函数是程序停止n秒后继续,n可以使分数或小数。函数的分辨率根据平台而定,大多数平台都能满足0.01秒的精度。
PAUSE causes a procedure to stop and wait for the user to strike any key before continuing.
可以使用PAUSE让程序停止运行直到用户敲击键盘。
PAUSE OFF indicates that any subsequent PAUSE or PAUSE(n) commands should not actually pause. This allows normally interactive scripts to run unattended.
PAUSE OFF 关闭之后所有的PAUSE函数的暂停功能。
PAUSE ON indicates that subsequent PAUSE commands should pause.
PAUSE ON 打开之后的所有PAUSE函数的功能。
MATLAB提供的用于图形控制的函数和命令:
axis: 人工选择坐标轴尺寸.
clf:清图形窗口.
ginput: 利用鼠标的十字准线输入.
hold: 保持图形.
shg:显示图形窗口.
subplot: 将图形窗口分成N块子窗口。
1.图形窗口(figure window)
(1). 图形窗口的创建和选择(Creating and selecting of figure window)
figure(n):用于为当前的绘图创建图形窗口,每运行一次figure就会创建一个新的图形窗口,n表示第n个
窗口,如果窗口定义了句柄,也可以用figure(h)将句柄h的窗口作为当前窗口。
clf :用于清除当前图形窗口中的内容。
shg :用于显示当前图形窗口。
(2). 在一个图形窗口中绘制多个子图形(Drawing several subfigures in a single window)
subplot(m,n,p):把窗口分成m×n个小窗口,并把第p个窗口当作当前窗口。
例:将4 个图形显示在同一个图形窗口中。
t=0:pi/20:2*pi; [x,y]=meshgrid(t);
subplot(2,2,1); plot(sin(t),cos(t)); axis equal
subplot(2,2,2); z=sin(x)+cos(y); plot(t,z); axis([0 2*pi –2 2])
subplot(2,2,3); z=sin(x).*cos(y); plot(t,z); axis([0 2*pi –1 1])
subplot(2,2,4); z=sin(x).^2-cos(y).^2; plot(t,z); axis([0 2*pi –1 1])
(3). 在一个已有的图形上绘图(Drawing a figure on the figure was existed)
hold on :在一个已有的图形上继续绘图;
hold off: 命令结束继续绘图。
例:将peaks函数的等高线图与伪彩色画在一起。
[x,y,z]=peaks; %产生双变量数组
contour(x,y,z,20,'k') %绘制等高线
hold on
pcolor(x,y,z) %绘制伪彩色图
shading interp %表面色彩渲染
hold off
2.坐标轴控制命令(Axis control commands)
控制坐标性质的axis函数的多种调用格式:
axis(xmin xmax ymin ymax) :指定二维图形x和y轴的刻度范围,
axis auto :设置坐标轴为自动刻度(缺省值)
axis manual(或axis(axis)):保持刻度不随数据的大小而变化
axis tight :以数据的大小为坐标轴的范围
axis ij :设置坐标轴的原点在左上角,i为纵坐标,j为横坐标
axis xy :使坐标轴回到直角坐标系
axis equal :使坐标轴刻度增量相同
axis square :使各坐标轴长度相同,但刻度增量未必相同
axis normal :自动调节轴与数据的外表比例,使其他设置失效
axis off :使坐标轴消隐
axis on :显现坐标轴
(1) 坐标轴的范围(Domain of coordinates axis)
二维图形坐标轴范围在缺省状态下是根据数据的大小自动设置的,如欲改变,可利用axis(xmin xmax ymin ymax),函数来定义。
例: 定义坐标轴范围对观察图形的影响。
x=0:.01:pi/2; figure(1); plot(x,tan(x),'-ro') %ymax=tan(1.57),而其他数据都很小,结果将
%使图形难于进行观察和判断。
figure(2); plot(x,tan(x),'-ro'); axis([0, pi/2,0,5]) %对坐标轴的范围进行控制就可得到较满意的绘图结果
(2) 显示比例对绘图结果的影响(Effect of display scaling on plotting results)
例:比较(Default, axis square, axis equal, axis tight)几种不同的显示方式的显示效果。
t=0:pi/20:2*pi; figure(1);
subplot(2,1,1); plot(sin(t),2*cos(t)); grid on %缺省状态下的图形比例
subplot(2,1,2); plot(sin(t),2*cos(t)); axis square; grid on %正方形的显示比例
figure(2)
subplot(1,2,1); plot(sin(t),2*cos(t)) ; axis equal; grid on %具有相等的刻度比例
subplot(1,2,2); plot(sin(t),2*cos(t)); axis tight ; grid on %紧缩形式
3.图形标注(Marking on the figure):MATLAB的图形标注方法(表 6—7)
title :标题,
xlabel :x轴标注,
ylabel :y轴标注,
text :任意定位的标注
gtext :鼠标定位标注,
legent :标注图例
图形标注可以使用字母,数字,汉字或按规定的方法表示希腊字母。如:\pi表示π,\leq表示≤,\rm表示后面的字恢复为正体字,\it表示斜体字,FontSize表示字体的大小, FontName表示字体的类型等。
可以使用图形窗口的Insert菜单,也可以使用属性编辑器,还可以使用函数输入的方法加标注,以下介绍相关函数的使用方法。
(1). 加注坐标轴标识和图形标题(Add axis labels and title of figure)
加注坐标轴标识:xlabel(‘s’), ylabel(‘s’)
图形标题: title(‘s’)
例:加注坐标轴标示和图形标题。
t=0:pi/100:2*pi;y=sin(t);
plot(t,y)
axis([0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel('sin(t)','FontSize',20)
title('正弦函数图形','FontName','隶书','FontSize',20)
(2). 图中加注文本(Add text in the figure)
text(x,y,’字符串’)
例:在上图中加语句。
t=0:pi/100:2*pi;
y=sin(t);
plot(t,y)
axis([0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel('sin(t)','FontSize',20)
title('正弦函数图形','FontName','隶书','FontSize',20)
text(3*pi/4,sin(3*pi/4),'\leftarrowsin(t)=0.707', 'FontSize',16)
text(pi,sin(pi),'\leftarrowsin(t)=0', 'FontSize',16)
text(5*pi/4,sin(5*pi/4),'sin(t)=-0.707\rightarrow','FontSize',16,...
'HorizontalAlignment','right')
句中:
leftarrow 表示加一个向左的箭头
rightarrow 表示加一个向右的箭头
HorizontalAlignment 表示右对齐水平排列
gtext('字符串'): 在图形窗口上用鼠标直接在指定的位置上加注文本。
例:
t=0:pi/100:2*pi;
y=sin(t);
plot(t,y)
axis([0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel('sin(t)','FontSize',20)
title('正弦函数图形','FontName','隶书','FontSize',20)
gtext('MATLAB')
(3). 指定TeX字符
例:在标题中指定TeX字符
t=0:pi/100:2*pi;
alpha=-0.8;
beta=15;
y=sin(beta*t).*exp(alpha*t);
plot(t,y)
title('{\itAe}^{-\it\alpha\itt}sin\it\beta{\itt}\it\alpha\it\beta')
xlabel('时间\mus.'),
ylabel('幅值')
在title中的字符串表现的是 Aeαt sinβt αβ
斜体Ae 上标斜体αt 斜体βt 斜体α 斜体β
(4). 在图形中添加图例框(Add legend in the figure)
legend(字符串1,字符串2,…)
例:在当前图形中添加图例说明。
x=0:pi/10:2*pi;
y1=sin(x);
y2=0.6*sin(x);
y3=0.3*sin(x);
plot(x,y1,x,y2,'-o',x,y3,'-*')
legend( '曲线1','曲线2','曲线3')
legend('boxoff')
legend函数的其他功能见(表 6—8)
4. 图线形式和颜色(Style and color of plot)
(1). 图线的形式: (style of plot)
四种线形: 实线'-',虚线'--', 点线':',点划线'-'.
标记点类型:点'.', 圆'o', 加号'+', 星号'*', x符号'x', 方形's', 菱形'd', hexagram 'h'
上三角△ '^', 下三角▽ 'v', 左三角'', 右三角'', 正五边形'p'
命令:plot(x,y,'—'), plot(x1,y1,':’,x2,y2,'*')
例1:选择不同的线形绘图。
t=0:pi/100:2*pi; y=sin(t); y2=sin(t-0.25); y3=sin(t-0.5);
plot(t,y,'-',t,y2,'-',t,y3,':')
例2:选择不同的标记点绘图。
t=0:pi/20:2*pi; x=t.^3; y=sin(t); plot(x,y,'o')
(2). 线的颜色(color of plot)
可选颜色: 红r,绿g, 蓝b, 黄y, 粉红m, 青c, 黑k.
例:t=0:pi/20:2*pi;
y=sin(t); plot(x,y,'r'), plot(x,y,'g+')
(3). 图线的其他属性(other characters of plot)
设置图线的宽度 : 'LineWidth'
标记点的边缘颜色: 'MarkerEdgeColor'
填充颜色 : 'MarkerFaceColor'
标记点的大小 : 'MarkerSize'
例: 设置图线的线形、颜色、宽度、标记点的颜色及大小。
t=0:pi/20:pi; y=sin(4*t).*sin(t)/2;
plot(t,y,'-bs','LineWidth',2,'MarkerEdgeColor','k', 'MarkerFaceColor', 'y','MarkerSize',10);
matlab 函数如何延时?
pause(n)表示延迟n秒再进行,其中n必须是正数。因此延迟5秒的命令是pause(5)。
官方解释:pause(n)
pauses
executionfor
n
seconds
before
continuing,
where
n
isany
nonnegative
real
number.
Pausing
must
be
enabled
for
this
to
takeeffect.
一般延迟用的比较少,我只是在浏览图片的时候用过,每隔3秒钟打开下一张图片。
pause在matlab中的作用是什么?
不加参数,直接用pause的话,就是程序暂停,直至用户按任意一个按键.
如果加参数.
比如pause(1.5)就是程序暂停1.5秒.