How do I wait for an appdesigner pushbutton press from a script

28 ビュー (過去 30 日間)
Gary Stirk
Gary Stirk 2016 年 12 月 22 日
回答済み: Gary Stirk 2017 年 1 月 3 日
I have created a matlab script which calls an app designer gui. The gui has a selection of raido buttons to select a system frequency to be simulated. I want to pause the script until a I've pushed a SUBMIT button that is in the GUI.
I am getting the app handle and button handle ok from the script and have it working waiting onthe closure of the gui using the waitfor() function but I can't seem to get it to waif for the gui Button to be pressed.
clear all;
close all;
global modFreq; % system Freq set in GUI from radio button
%%instantiate my gui
guiHandle = mySystemConfigGui;
buttonHandle = guiHandle.RunButton;
%
waitfor(guiHandle);
fprintf('continuing script..\n');
How do I wait for an appdesigner pushbutton press from a script

採用された回答

Aylin
Aylin 2016 年 12 月 27 日
Hello Gary,
You can use the uiwait function with the uiresume function instead of the waitfor function in order to pause execution while waiting for a button press. Please see the uiwait documentation page for an example:
https://www.mathworks.com/help/matlab/ref/uiwait.html
Note that you may have to register a new callback function in the button in order to run the uiresume function.
Rylan

その他の回答 (2 件)

Gary Stirk
Gary Stirk 2017 年 1 月 3 日
Thanks Rylan,
This definitely got me over the hump. For a novice like myself the doc was not completely clear so I've given my final solution below possibly to help others. Notes:
1. The gui was created using app designer
2. I had to make the uiwait() parameter the giuFigure handle not the button handle.
3. Added the uiresume() with the parameter being the guiFigure handle used in the uiwait() of the .m program.
MatLab.m relevant code:
%%instantiate my gui
guiHandle = mySystemConfigGui;
%
guiFigureHandle = guiHandle.myConfigurationUIFigure;
uiwait(guiFigureHandle);
fprintf('continuing script..\n');
gui RunPushButtonPushed callback
% Button pushed function: RunButton
function RunButtonPushed(app, event)
uiresume(VeridianConfigurationUIFigure);
end

Gary Stirk
Gary Stirk 2017 年 1 月 3 日
gui RunPushButtonPushed callback correction (uiresume() parameter should have had 'app.'prefix
% Button pushed function: RunButton
function RunButtonPushed(app, event)
uiresume( app.VeridianConfigurationUIFigure);
end

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by