Exchanging data between Matlab and Simulink in rapid accelerator mode

1 Ansicht (letzte 30 Tage)
sali
sali am 21 Jan. 2019
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(...
M,...
'U11',PartialArray(1,1,page),...
'U12',PartialArray(1,2,page),...
'U13',PartialArray(1,3,page),...
'U21',PartialArray(2,1,page),...
'U22',PartialArray(2,2,page),...
'U23',PartialArray(2,3,page),...
'U31',PartialArray(3,1,page),...
'U32',PartialArray(3,2,page),...
'U33',PartialArray(3,3,page),...
'Y11ini',PartialY(1,1,page),...
'Y12ini',PartialY(1,2,page),...
'Y13ini',PartialY(1,3,page),...
'Y21ini',PartialY(2,1,page),...
'Y22ini',PartialY(2,2,page),...
'Y23ini',PartialY(2,3,page),...
'Y31ini',PartialY(3,1,page),...
'Y32ini',PartialY(3,2,page),...
'Y33ini',PartialY(3,3,page));
idx = idx+1;
end
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;
end
Yout=zeros(10000,1,10000);
out = cell(1, numSimCmdArgStructs);
l=1;
parfor(i = 1:numSimCmdArgStructs)
out{i} = sim(mdl, simCmdParamValStructs{i});
end
for i=1:numSimCmdArgStructs
t = out{i}.find('tout');
y = out{i}.find('Y22');
PartialY(2,2,i)=y(end);
Yout(i,1,l)=y(end);
end

Antworten (0)

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!

Translated by