Pause button not functioning

6 visualizaciones (últimos 30 días)
Vijay
Vijay el 27 de Nov. de 2024
Movida: Walter Roberson el 15 de Dic. de 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?
  1 comentario
lakshmikanth
lakshmikanth el 15 de Dic. de 2024
Movida: Walter Roberson el 15 de Dic. de 2024
run button is not working

Iniciar sesión para comentar.

Respuestas (3)

Matt J
Matt J el 27 de Nov. de 2024
Editada: Matt J el 27 de Nov. de 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 el 27 de Nov. de 2024
Editada: Image Analyst el 27 de Nov. de 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 el 27 de Nov. de 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!

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by