How do I run a script from a GUI that will run in the 'base' workspace?

조회 수: 55(최근 30일)
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
Walter Roberson
Walter Roberson 2016년 2월 25일
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 :(

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 25일
evalin('base', 'name_of_script')
  댓글 수: 4
Arif Kilic
Arif Kilic 2020년 6월 19일
don't use .m. just write your script name

댓글을 달려면 로그인하십시오.

추가 답변(1개)

pjman yucifee
pjman yucifee 2018년 4월 10일
Very nice.....Thanks a lot

Community Treasure Hunt

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

Start Hunting!

Translated by