How to control GUI with external m-file

조회 수: 1 (최근 30일)
Leo Zhai
Leo Zhai 2019년 12월 12일
댓글: Leo Zhai 2019년 12월 19일
I created a GUI, named 'StartEngine', there is a button 'Run'(handles.pushbutton1) on the GUI.
Now, I opened the GUI and I want to make Background color of this button to be gray with a m-file.
It means how could I implement the following command out of StartEngine.m (corresponding to StartEnge.fig)
set(handles.pushbutton1, 'BackgroundColor', [0.5, 0.5, 0.5]);
  댓글 수: 11
Leo Zhai
Leo Zhai 2019년 12월 18일
Hi,
after I run the your first line (GUI already opened)
figs = findall('type', 'figure');
the following errors show:
Error using findall (line 24)
Invalid handles passed to findall
Walter Roberson
Walter Roberson 2019년 12월 18일
figs = findall(0, 'type', 'figure');
get(figs, 'Name')
get(figs, 'Tag')

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

채택된 답변

Leo Zhai
Leo Zhai 2019년 12월 18일
I figure out an alternative solution, which do NOT use "control GUI with external m-file" but use "GUI control itself with feedback of external m-file"
test4.jpg
Before, I thought the GUI(StartEngine.m) and the external m-file(ExcuteRun.m) run parallel, GUI will not "wait for" the external m-file runing to end and get its result/output.
Now, I found the code is "single-thred", GUI will continue after external m-file run to end.
test5.jpg
By the way, I did not find error until now. I wonder if some risk exists using this way.
  댓글 수: 4
Adam Danz
Adam Danz 2019년 12월 19일
Sounds like a decent plan, except part 2 ;)
One difficulty you may experience is troubleshooting any of those components when something goes wrong. Let's say you have a variable named "V" in one of the xx.m files in the bottom row. V should always be a positive integer but you noticed it's value is NaN. You have no idea where that value is coming from. It could come from any of these possibilities:
  • from StartEngine
  • from xx.m #1
  • from xx.m #2
  • From within ExecuteRun.m
  • from an interaction in ExecuteRun between StartEngine and xx.m #1
  • from an interaction in ExecuteRun between StartEngine and xx.m #2
  • from an interaction in ExecuteRun between xx.m #1 and xx.m #2 within
and lots of other possibilities. This organization often make reproducibility difficult or even impossible.
One way to deal with many input and output variable is to organize them into a structure. For example,
function [motion, position] = movingObject(action)
end
Where the ouputs & inputs contains many fields
motion.velocity
motion.acceleration
motion.previousPosition
motion.currentPosition
% etc...
Anyway, I'm sure you'll figure this stuff out soon.
Leo Zhai
Leo Zhai 2019년 12월 19일
Thanks for your greate advice, I will think through it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by