Accessing variables from a Simulink model initFcn callback with parsim
Ältere Kommentare anzeigen
I'm running a model in parallel using parsim. I define all the variables used by the model with the setVariable method of a Simulink.SimulationInput object. All works fine until I try to access one of this variables from the initFcn callback.
Aparently, the variables defined in the model workspace, that are accesible from the model itself, are not accessible from the callbacks. Is there any way of defining a variable for the SimulationInput object, that can be accessed from the model callbacks when using parsim?
This is a dummy example of what I'm trying to do:
%% Create an array of input data
n = 10;
Av = (1:n)*50;
Bv = (1:n)*100;
t = 0:1e-3:10;
for i =1:n
simInput.A = Av(i);
simInput.B = Bv(i);
in(i) = Simulink.SimulationInput('parsimTest');
in(i) = in(i).setVariable('simInput',simInput,'Workspace','parsimTest');
in(i) = in(i).setModelParameter('StopTime','7.5');
end
%% Run in paralell
out = parsim(in,'ShowSimulationManager','on');
And this is the model and the initFcn callback:

I already tried to use the option
'TransferBaseWorkspaceVariables','on'
within the parsim function. That would work if the variable I try to access in the initFcn is constant over the parallel simulations, but I need it to change.
Thanks in advance!
Guillermo
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Run Individual Simulations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!