Exchanging data between Matlab and Simulink in rapid accelerator mode

1 view (last 30 days)
Hi all,
I run this code without any error but it seems there is a hidden issue in the communication between the matlab and the simulink model, I am using rapid accelerator mode in this part of my code: in the simulink model I have 9 constant blocks U11 to U33 which should receive different data in each iteration of the parfor, also I have "To Workspace" block which should send back Y22 but when I checked the workspace I did not find Y22 and the final results are wrong, is there any thing I missed?
I created another file and changed the constant blocks to inport and I imported the data but I had an error.
Any help would be appreciated.
numParamSets = 10000;
% Create parameter sets:
assignin('base',['Y11ini' ],0);
assignin('base',['Y12ini' ],0);
assignin('base',['Y13ini' ],0);
assignin('base',['Y21ini' ],0);
assignin('base',['Y22ini' ],0);
assignin('base',['Y23ini' ],0);
assignin('base',['Y31ini' ],0);
assignin('base',['Y32ini' ],0);
assignin('base',['Y33ini' ],0);
paramSets = cell(1, numParamSets);
idx = 1;
M = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
for page = 1:10000
paramSets{idx} = Simulink.BlockDiagram.modifyTunableParameters(...
idx = idx+1;
numSimCmdArgStructs = numParamSets;
simCmdParamValStructs = cell(1, numSimCmdArgStructs);
paramValStruct.SaveTime = 'on';
paramValStruct.SaveOutput = 'on';
paramValStruct.SimulationMode = 'rapid';
paramValStruct.RapidAcceleratorUpToDateCheck = 'off';
paramValStruct.RapidAcceleratorParameterSets = [];
paramValStruct.LimitDataPoints = 'off';
idx = 1;
for paramSetsIdx = 1:numParamSets
simCmdParamValStructs{idx} = paramValStruct;
simCmdParamValStructs{idx}.RapidAcceleratorParameterSets = paramSets{paramSetsIdx};
idx = idx + 1;
out = cell(1, numSimCmdArgStructs);
parfor(i = 1:numSimCmdArgStructs)
out{i} = sim(mdl, simCmdParamValStructs{i});
for i=1:numSimCmdArgStructs
t = out{i}.find('tout');
y = out{i}.find('Y22');

Answers (0)

Community Treasure Hunt

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

Start Hunting!