Pause button not functioning

조회 수: 15 (최근 30일)
Vijay
Vijay 2024년 11월 27일
이동: Walter Roberson 2024년 12월 15일 18:58
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
lakshmikanth
lakshmikanth 2024년 12월 15일 17:18
이동: Walter Roberson 2024년 12월 15일 18:58
run button is not working

댓글을 달려면 로그인하십시오.

답변 (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에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by