Passing Parameters from GUI to Script
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Matt Fig
le 6 Sep 2012
Modifié(e) : Matt Fig
le 6 Sep 2012
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;');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!