How can I set the source workspace to "caller" when using a the SIM command from a function in Simulink 7.4 (R2009b)?
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
MathWorks Support Team
am 19 Aug. 2011
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!