Main Content

uiwait

阻止程序执行并等待恢复

说明

uiwait 阻止程序执行,直至调用了 uiresume 函数或删除了当前图窗 (gcf)。

uiwait 函数阻止 MATLAB® 和 Simulink® 程序执行。uiwait 还阻止 Simulink 模型的执行。

示例

uiwait(f) 阻止程序执行,直至调用了 uiresume 函数或删除了图窗 f。该图窗可以是使用 figureuifigure 函数创建的。

使用 uiwait 函数和模态对话框可阻止程序执行限制用户交互仅在对话框中进行,直到用户对它作出响应。

示例

uiwait(f,timeout) 阻止程序执行,直至调用了 uiresume、删除了图窗或经过了 timeout 秒。

示例

全部折叠

创建一个警报对话框并等待用户响应它,然后允许程序继续执行。

在 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')

Alert dialog box in a UI figure window with a plot. The dialog box text says: "A line plot was created in the axes."

阻止程序继续执行,直到用户响应模态消息对话框。

在图窗中创建一个线图并显示模态消息对话框。当用户点击确定或关闭对话框时,请等待对话框被删除。当程序继续执行时,在命令行窗口中显示一条消息。

f = figure;
plot(1:10)
msgfig = msgbox('Operation was completed successfully!','Success','modal');
uiwait(msgfig)
disp('Program execution resumed.');

A modal dialog box displays in front of a figure window that contains a line plot.

创建一个继续按钮,并等待用户按下它。然后显示一条消息。

创建一个具有回调的普通按钮,当点击该普通按钮时会调用 uiresume 函数。等待用户点击继续或关闭图窗窗口。然后显示一条消息。

f = figure('Position',[500 500 400 300]);
c = uicontrol('String','Continue','Callback','uiresume(f)');
uiwait(f)
disp('Program execution has resumed');

A "Continue" button displays in the lower-left corner of a figure window.

创建一个在经过指定时间后会关闭的图窗。

在 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

输入参数

全部折叠

图窗对象,指定为使用 figureuifigure 函数创建的 Figure 对象。

超时持续时间,指定为以秒为单位的数值。请指定大于或等于 1 的数字。

详细信息

全部折叠

模态对话框

模态对话框阻止用户在响应该对话框之前与其他 MATLAB 窗口进行交互。

版本历史记录

在 R2006a 之前推出

另请参阅

| |