How can I set the source workspace to "caller" when using a the SIM command from a function in Simulink 7.4 (R2009b)?

In previous releases I was using the following command to specify to the SIM command to use the "current" workspace instead of the "base" workspace when called from inside a function:
[t,x,y] = sim(bdroot,simset('srcworkspace','current'))
In R2009b, the SIMSET function has been deprecated.

 采纳的回答

This backward incompatibility in Simulink 7.4 (R2009b) was necessary for the SIM command to be compatible with the parallel computing command PARFOR.
In order to work around this issue, it is recommended to assign the required variables to the model workspace. For example, inside the function use:
hws = get_param(model, 'modelworkspace');
% Here it is possible to define as many parameters as possible
a = 5;
list = whos; % Get the list of variables defined in the function
N = length(list);
% Assign everything in the model workspace
for i = 1:N
hws.assignin(list(i).name,eval(list(i).name));
end
See attached files for a complete example.
If you are not planning to use the SIM command inside a PARFOR loop, it is possible to pass a "SrcWorkspace" parameter to the SIM command, for example:
simOut = sim( mymodel, 'SrcWorkspace', 'current')

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品

版本

R2009b

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by