Simulink - Rapid Accelerator with varying inputs

2 Ansichten (letzte 30 Tage)
TeichEnterich95
TeichEnterich95 am 30 Apr. 2021
Beantwortet: nick am 3 Okt. 2024
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

Antworten (1)

nick
nick am 3 Okt. 2024
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!

Kategorien

Mehr zu Prepare Model Inputs and Outputs finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by