Passing Parameters from GUI to Script
조회 수: 2 (최근 30일)
이전 댓글 표시
I have GUI that I'm working on as a front end to an existing script. A partner of mine helps with the script, so I would like to keep it as a separate file. I'm attempting to pass the GUI handles as a struct object to the script, the script then takes the values from the handles and creates variables in the base workspace which will be used by a Simulink model.
When the user has input all the parameters, they hit a "Go" button which then calls the other script.
I've read other forum postings on this, and the closest I've come to success if the following callback:
% --- Executes on button press in Go.
function Go_Callback(hObject, eventdata, handles)
assignin('base','hnd',handles);
setup;
When the "Go" button is pressed, it generates an error:
Undefined variable "hnd" or function "hnd.Load_Sin".
Error in setup (line 66)
csim.motor3_for_test = get(hnd.Load_Sin,'Value'); %NO
It doesn't matter what object I try to call from hnd, the first one in the script always generates an error.
The odd thing is, if I then go an manually run setup.m, it runs fine.
It's acting like it's running setup.m before the assignin command, even though assignin is clearly before it.
I may have other end users who will run this script and I don't want them to have to jump through hoops to get it to run. What do I need to do so it executes correctly from pressing the Go button?
댓글 수: 0
채택된 답변
Matt Fig
2012년 9월 6일
편집: Matt Fig
2012년 9월 6일
If setup is a script, you are actually running it from in the callback. If that is o.k., try this:
function Go_Callback(hObject, eventdata, handles)
hnd = handles;
setup;
if not, you will have to do this:
function Go_Callback(hObject, eventdata, handles)
assignin('base','hnd',handles);
evalin('base','setup;');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!