Pause button not functioning

6 次查看(过去 30 天)
Vijay
Vijay 2024-11-27
移动Walter Roberson 2024-12-15
In MATLAB R2023b, I have a program that displays a figure inside a while loop and uses the "pause" command to allow the user to modify the figure before pressing the space key to open a dialog for accepting the plot. When running the program in MATLAB, it waits for the user to press the space key before displaying the dialog. However, after compiling the program into a standalone application using MATLAB Compiler, the executable does not wait for user input before showing the dialog.
Why does the "pause" command not function in standalone applications?
How can I pause the figure until the user provides input to display the dialog?
Why does the "pause" command not function in standalone applications?How can I pause the figure until the user provides input to display the dialog?

回答(3 个)

Matt J
Matt J 2024-11-27
编辑:Matt J 2024-11-27
Try using waitfor instead, along with some sort of uicontrol, e.g.,
% Create the figure
fig = figure;
% Add a button to indicate readiness
readyButton = uicontrol('Style', 'pushbutton', 'String', 'Continue', ...
'Position', [20, 20, 100, 30], 'Callback', 'set(gcf, ''UserData'', true)');
% Set the figure's UserData to false initially
set(fig, 'UserData', false);
% Wait until the UserData property is true
waitfor(fig, 'UserData');
disp('User pressed the button. Continuing...');

Image Analyst
Image Analyst 2024-11-27
编辑:Image Analyst 2024-11-27
Try uiwait and helpdlg
while whatever
% Make some figure in the loop
hFig = figure;
% Then pause asking user to make any changes.
uiwait(helpdlg('Make adjustments to the figure then click OK.'))
% Close this figure and continue with the loop.
close(hFig);
end
(It might not work if it's a modal dialog box though). You could also try questdlg.

Gayatri
Gayatri 2024-11-27
Hi Vijay,
The 'pause' function cannot receive input when running in a standalone application built as a Windows application. To enable pause to accept input in a standalone application, it must be built as a console application.
If the application cannot be built as a console application, to work around this issue, please do the following:
1. When making the figure creation call, please add an event to the figure by replacing the "figure" line with:
figure('KeyPressFcn',@(obj,evt) 0);
2. Then, replace the "pause" code with a "waitfor" such as waiting for the current character input to be a space character:
waitfor(gcf,'CurrentCharacter', ' ');
For more details on the 'waitfor' function, refer to the below documentation:
I hope it helps!

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by