Error using sim command
15 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Fangjun Jiang
2019-1-31
sim() is a build-in command. It looks like you have a S-function called sim??
Run "which -all sim" to see if there is anything suspecious.
2 个评论
Fangjun Jiang
2019-1-31
To avoid conflicts, you have to rename your S-function and re-mex it. That is the only solution. For the meantime, you can remove the U:\..path ..\ from your MATLAB path and then you should be able to use the built-in sim() command.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!