Running a script from a function and use the 'base' workspace for that script

I am making a GUI using GUIDE. My intention is to have a script that is already available to be ran when pressing a push button, using the push button callback.
The script uses variables from 'base' workspace.
Naturally, MATLAB gives an error - I assume it is because anything ran from the callback function will attempt to use the callback functions workspace.
The reason why I cannot run the script from within the callback is that other functions are contained in the script, specifically ones that use a SIMULINK model. My experience with nested functions running SIMULINK models ended in avoiding the use of SIMULINK in that manner - if I have SIMULINK block fields obtain a parameter value from a workspace or put one in there, it goes into 'base'; but with nested functions MATLAB tells me that it cannot write any variables.
Hence I'd like to avoid running my script from the callback.
How could I trigger my script from the GUI pushbutton callback, but run the script in 'base' workspace?
P.S. I've considered the use of simset - it seems the function is now obsolete.

2 件のコメント

Ben11
Ben11 2015 年 1 月 16 日
Have you looked into setappdata and getappdata to share your variables from one workspace to another?
per isakson
per isakson 2015 年 1 月 16 日
see assignin and evalin, but ...

サインインしてコメントする。

回答 (1 件)

Abdesslem Nekkache
Abdesslem Nekkache 2020 年 4 月 10 日
should be like this
evalin('base', 'x=1;')

1 件のコメント

Brent F
Brent F 2021 年 6 月 23 日
The only way to create aliases that run in the main workspace. For example:
function [] = cls ()
evalin('base', 'clearvars; clc;');
end

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Environment Customization についてさらに検索

質問済み:

2015 年 1 月 16 日

コメント済み:

2021 年 6 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by