Simulink - Rapid Accelerator with varying inputs
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am running my Simulink model 'MyModel' -times in a script (let's call it 'MyScript.m') as it can be seen below. The goal is to build the model in rapid accelerator mode outside of the for-loops and then run the model -times with varying inputs. My Simulink 'MyModel' has 5 root level inputs with a fixed sampling time. The signals 'signal1' - 'signal5' are double workspace variables.
When running the script, I get the following:
Building the rapid accelerator target for model: MyModel
Successfully built the rapid accelerator target for model: MyModel
Error using MyScript (line 25) [Error occurs in the line with the 'sim' command]
In 'Simulink:Logging:UTInvDim', parameter {1} must be a real scalar.
I know that it is probably difficult to solve this problem without having access to the Simulink model. However, maybe someone can tell me if this the right way to run a Simulink model in rapid accelerator mode with varying inputs in general.
model = 'MyModel';
% Build rapid accelerator target
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(model);
% Create simulation object
sim_object = Simulink.SimulationInput(model);
% Set model parameters
sim_object = sim_object.setModelParameter('SimulationMode','rapid','StartTime','0','ReturnWorkspaceOutputs','on');
for i = 1:N
for ii = 1:M
% Set stop time
sim_object = sim_object.setModelParameter('StopTime','1');
% Set input signals of 'MyModel'
sim_object = sim_object.setExternalInput(signal1);
sim_object = sim_object.setExternalInput(signal2);
sim_object = sim_object.setExternalInput(signal3);
sim_object = sim_object.setExternalInput(signal4);
sim_object = sim_object.setExternalInput(signal5);
% Start simulation
sim(sim_object)
end
end
댓글 수: 0
답변 (1개)
nick
2024년 10월 3일
The error you're encountering suggests an issue with how inputs are being set up and passed to the model. The 'setExternalInput' function should be used to specify all inputs using a single variable, as shown:
% Loop over N and M
for i = 1:N
for ii = 1:M
% Set stop time
sim_object = sim_object.setModelParameter('StopTime','1');
% Assuming signal1, signal2, ..., signal5 are time series with the same time vector
timeVector = signal1.Time;
% Concatenate signals into a single matrix
inputData = [timeVector, signal1.Data, signal2.Data, signal3.Data, signal4.Data, signal5.Data];
sim_object = sim_object.setExternalInput(inputData);
simOut = sim(sim_object);
end
end
You may refer to the following documentation to know more about 'setExternalInput' function:
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Prepare Model Inputs and Outputs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!