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!