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

采纳的回答

Fangjun Jiang
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 个评论
Michael Knörzer
Michael Knörzer 2019-1-31
First of all, thank you for the response.
I think you`re right. I get
U:\ ...path ...\sim.mex64
built-in (C:\ ...path ....\sim) % Shadowed
Is there a way to indicated that I want to use the original sim command without renaming the sfunction?
Or is it possible to run the previously mentioned code using another command?
Fangjun Jiang
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 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by