Pause button not functioning

4 views (last 30 days)
Vijay
Vijay on 27 Nov 2024
Moved: Walter Roberson on 15 Dec 2024
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?

Answers (3)

Matt J
Matt J on 27 Nov 2024
Edited: Matt J on 27 Nov 2024
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 on 27 Nov 2024
Edited: Image Analyst on 27 Nov 2024
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 on 27 Nov 2024
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!

Categories

Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!