MATLAB GUI Workspace problem
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Paulo Silva
2011-8-2
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!