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!