How to use Cell array as block parameter using setBlockParameter in Simulink?
Afficher commentaires plus anciens
I apologize if this has be answered before, but I couldn't find anything. I could be using the wrong phrasing to search.
I have a version of the EV example model that comes with the 2022b version of MATLAB. I have my own drive cycles that I would like to run in it. I have those drive cycles in a cell array in the workspace. If I run each cycle one at a time using button simulation commands it works, but if I use the sim commands in a for loop I get an error.
Here is how I currently am doing it:
load_system('EVModel');
param1 = CycleCell{1};
set_param('EVModel/Drive Cycle Source', 'cycleVar', 'Workspace variable');
set_param('EVModel/Drive Cycle Source', 'wsVar', 'param1');
simOut = sim("EVModel");
That code works fine, but the problem is that I have a few hundred cycles to run so I would like to do it in a loop.
Here is what I am trying:
model = 'EVModel';
load_system(model);
simIn(1:length(CycleCell)) = Simulink.SimulationInput(model);
for i = 1:length(CycleCell)
param = CycleCell{i};
simIn(i) = simIn(i).setBlockParameter('EVModel/Drive Cycle Source', 'cycleVar', 'Workspace variable');
simIn(i) = simIn(i).setBlockParameter('EVModel/Drive Cycle Source', 'wsVar', 'param');
end
simOut = parsim(simIn);
For this code I keep getting the error: "Warning: One or more simulations completed with errors. For more information, inspect the
SimulationOutput objects at these indices:".
and in the SimulationOutput object it has: "Error in '<a href="matlab:open_and_hilite_hyperlink ('EVModel/Drive Cycle Source','error')">EVModel/Drive Cycle Source</a>': Failed to evaluate mask initialization commands.Caused by: Dot indexing is not supported for variables of this type."
I cannot find what I am doing wrong. If this is possible, there must be something that I am missing. Also, I do have the Parallel Computing Toolbox.
Any ideas what is wrong?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programmatic Model Editing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
