How can i execute a GUI from a .m script?
48 ビュー (過去 30 日間)
古いコメントを表示
Hello everybody!
I have created a .m script that makes some calculations. The thing is that in the middle of the script, i need the user to tell me which transformation should he choose (it is just one step from the whole script), for every rectangle in a given grill. So i created a GUI wich contains 5 buttons (the transformations options).
My problem is that i don't certainly know how to execute the GUI in my script.... is there a function or a command for that? How can i access it from the .m?
Thanks for your attention,
BRD
0 件のコメント
採用された回答
Geoff Hayes
2014 年 11 月 28 日
Brian - have you created your GUI through GUIDE or built it yourself using a script? Either way, you will have an m file which you can call directly from your current script as
% my other code
% launch GUI
myGUI;
% continue with script
where myGui.m is the name of you GUI m file. The trick with the above is how to wait, in the script, for your GUI to finish because you don't want the remainder of your script to be executed while the user is choosing a transformation.
Suppose that your GUI name/tag is tformChoiceGui and its HandleVisibility property is on, both which have been set using the GUIDE property editor for your figure/GUI. Or, if manually creating your GUI, you have done something like
hFig = figure;
set(hFig,'Tag', 'tformChoiceGui','HandleVisibility','on');
% continue to build GUI
You can then use the findobj to get the handle to your GUI, and wait for it to be closed/deleted using waitfor which will block execution until the GUI has been closed. Your code then becomes
% my other code
% launch GUI
myGUI;
% get the handle to the GUI and wait for it to be closed
hGui = findobj('Tag','tformChoiceGui');
waitfor(hGui);
% continue with script
See the attached (very simple) example of a script, myScript, that launches myGui and waits for it to close. One thing that is obviously missing is how to get the transformation choice from your GUI back to the script. How are you planning on doing this (without using global variables)?
1 件のコメント
giacomo
2017 年 11 月 23 日
How can I change the very first line:
hFig = figure;
if I want the remainder code to run after I close my GUI called mygui? I tried the easy:
hFig = mygui;
But then the mygui interface keeps flashing on my screen and I can't even use it. Thanks.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!