Error using sim command

15 visualizaciones (últimos 30 días)
Michael Knörzer
Michael Knörzer el 31 de En. de 2019
Comentada: Fangjun Jiang el 31 de En. de 2019
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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 31 de En. de 2019
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 comentarios
Michael Knörzer
Michael Knörzer el 31 de En. de 2019
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 el 31 de En. de 2019
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by