Error using sim command
Show older comments
Hello
I´m trying to simulate a simulink model/two different ones in a matlab script within a for loop using the sim command.
According to matlab documentation it should be possible to type either one of the following commands:
simOut = sim(model,ConfigSet)
simOut = sim(model)
My code looks like this:
mdl1 = 'TorquePressureModel1';
mdl2 = 'TorquePressureModel1';
cs = getActiveConfigSet(mdl1);
mdl_cs = cs.copy;
set_param(mdl_cs, ...
'SaveState','on','StateSaveName','xoutNew',...
'SaveOutput','on','OutputSaveName','youtNew')
for i = 1:2
if i == 1
simOut = sim(mdl1, mdl_cs);
elseif i == 2
simOut = sim(mdl2, mdl_cs);
end
...
I figured that this constructions works sometimes and sometimes it does not. And I get the same error using just
simOut = sim(mdl1);
The error is:
Error using sim
MEX level2 S-function "sim" must be called with at
least 4 right hand arguments
Error in AuswertungModellergebnisse (line 24)
simOut = sim(mdl1, mdl_cs);
If I use the command with 4 right hand arguments like
simOut = sim(mdl1, 'SaveState','on','StateSaveName','xoutNew',...
'SaveOutput','on','OutputSaveName','youtNew');
I get another error saying
Error using sim
The 4th right hand argument, FLAG, passed to MEX level2
S-function "sim" must be an integer
Error in AuswertungModellergebnisse (line 24)
simOut = sim(mdl1,
'SaveState','on','StateSaveName','xoutNew',...
Aren`t both of these ways of calling the sim command correct according to matlab documentation?
And why won`t they work?
I`m using matlab R2017a V9.2 and Simulink R2017a V8.9.
Thanks very much,
Michael
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!