uiwait
阻止程序执行并等待恢复
说明
uiwait
阻止程序执行,直至调用了 uiresume
函数或删除了当前图窗 (gcf
)。
uiwait
函数阻止 MATLAB® 和 Simulink® 程序执行。uiwait
还阻止 Simulink 模型的执行。
示例
等待对警报对话框的响应
创建一个警报对话框并等待用户响应它,然后允许程序继续执行。
在 UI 图窗中创建一个线图,并显示警报对话框。为对话框指定一个 CloseFcn
回调,该对话框在用户响应它时调用 uiresume
函数。等待用户在对话框中点击确定或将其关闭。当程序继续执行时,在命令行窗口中显示一条消息。
fig = uifigure; fig.Position = [500 500 500 350]; ax = uiaxes(fig); plot(ax,1:10) uialert(fig,'A line plot was created in the axes.', ... 'Program Information','Icon','info','CloseFcn','uiresume(fig)') uiwait(fig) disp('Program execution resumed')
等待对模态消息对话框的响应
阻止程序继续执行,直到用户响应模态消息对话框。
在图窗中创建一个线图并显示模态消息对话框。当用户点击确定或关闭对话框时,请等待对话框被删除。当程序继续执行时,在命令行窗口中显示一条消息。
f = figure; plot(1:10) msgfig = msgbox('Operation was completed successfully!','Success','modal'); uiwait(msgfig) disp('Program execution resumed.');
等待按钮按下
创建一个继续按钮,并等待用户按下它。然后显示一条消息。
创建一个具有回调的普通按钮,当点击该普通按钮时会调用 uiresume
函数。等待用户点击继续或关闭图窗窗口。然后显示一条消息。
f = figure('Position',[500 500 400 300]); c = uicontrol('String','Continue','Callback','uiresume(f)'); uiwait(f) disp('Program execution has resumed');
等待超时
创建一个在经过指定时间后会关闭的图窗。
在 UI 图窗中创建一个线图。
fig = uifigure; fig.Position = [500 500 500 350]; ax = uiaxes(fig); plot(ax,1:10);
创建一个 5 秒的超时。然后,在 try
模块内调用 close
函数来关闭图窗。如果图窗已关闭,catch
模块将阻止错误图窗句柄无效
显示,并允许代码继续正常执行。
uiwait(fig,5) try close(fig) catch end
输入参数
f
— 图窗对象
Figure
对象
图窗对象,指定为使用 figure
或 uifigure
函数创建的 Figure
对象。
timeout
— 超时持续时间
数值
超时持续时间,指定为以秒为单位的数值。请指定大于或等于 1
的数字。
详细信息
模态对话框
模态对话框阻止用户在响应该对话框之前与其他 MATLAB 窗口进行交互。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)