Pause button not functioning
조회 수: 15 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Matt J
2024년 11월 27일
편집: Matt J
2024년 11월 27일
% 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...');
댓글 수: 0
Image Analyst
2024년 11월 27일
편집: Image Analyst
2024년 11월 27일
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
댓글 수: 0
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!