How do I run a script from a GUI that will run in the 'base' workspace?
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John Petersen
le 25 Fév 2016
Commenté : Arif Kilic
le 19 Juin 2020
I have a simulink model that uses a lot of variables from the base workspace. Now I am making a GUI that runs the model, but I want to be able to reinitialize the base workspace by calling the script that does this. But I want to do it from the GUI. How do I run a script as if in the base workspace so that it populates all the variables there? I could use assignin('base', var, reinitvar), but this would be extremely tedious for all the variables. Is there another option?
3 commentaires
Walter Roberson
le 25 Fév 2016
It is because Simulink "From Workspace" blocks get their values from the Base workspace if the model is invoked by double-clicking on it or by using the menus. However, if the model is invoked by a MATLAB function running the sim() command, then From Workspace gets its variables from the workspace of the function that has the sim() call. I gather, however, that it is not uncommon for From Workspace blocks to somehow be configured to look only in the Base workspace.
Simulink bypasses normal workspace encapsulation sometimes :(
Réponse acceptée
Walter Roberson
le 25 Fév 2016
evalin('base', 'name_of_script')
4 commentaires
Sanjeev Kumar
le 26 Fév 2019
Thanks!!
But its not working while using the same command in Callback function of a button in Matlab GUIDE.
Ex:
function Button_callback(hObject,eventdata,handles)
evalin('base','MyScript.m');
end
An error is coming like:Undefined variable 'MyScript.m' or class 'MyScript.m'
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!