Passing Parameters from GUI to Script
3 次查看(过去 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 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!