Filter löschen
Filter löschen

MATLAB GUI Workspace problem

2 Ansichten (letzte 30 Tage)
Benjamin
Benjamin am 2 Aug. 2011
Okay So I am making a MATLAB GUI to run certain Simulink models and I want my program to be able to run any Simulink model, even ones which use a .m file to set their variables.
So I tried to run this code in a button callback
% vars.m is a file with the variable for the simulation
vars.m
% mySim is the simulink model
sim('mySim')
This does not work because it cannot see the variable ran from vars.m
now I ran the .m file in MATLAB and then ran the program again and this time the simulation ran properly.
So what I have figured out is that the variable when you run them in the GUI environment are stored in a place called "magical faerie land" or the gui workspace and not in the base workspace so when you run Simulink models in that same workspace they do not see the gui workspace and cannot run.
There are two solutions neither of which I know how to implement.
1) Tell Simulink to read the variable from the gui workspace
2) Tell the gui to run the .m file in the "base" workspace
Any help would be appreciated!

Akzeptierte Antwort

Paulo Silva
Paulo Silva am 2 Aug. 2011
Look at the documentation from the simset function, you can change the workspace from the default MATLAB Workspace to your own GUI function where you call the simulation
SrcWorkspace {base} | current | parent
opt=simset('SrcWorkspace','current')
sim('mySim',opt)
Another way is to run the m file on your GUI and use the code from
but the first option I provided is better, use save to base just if you really want to have the variables available on your workspace.
Finally please appreciate the help provided by MATLAB Answers users because you have already asked several questions but none is accepted, in some of them or maybe all you didn't even said thank you, we are real people not pieces of software, thank you.

Weitere Antworten (0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by