while loop in simscape language

8 visualizaciones (últimos 30 días)
Tomas Iesmantas
Tomas Iesmantas el 7 de Jun. de 2011
Respondida: Vishnu Teja Vithala el 9 de Jul. de 2018
Hi, I'm having some troubles in creating ssc file where I need to use while loop (or maybe for). Here is my code:
parameters
gain = { [0 0 1/3], '1' }; % Gain
max={[0.3 0.1 0.25],'1'} %Maximum pressures
end
parameters
stop = { 0, '1' };
k={1,'1'};
end
equations
while stop<1
if I<=sum(max(1:k))
stop=1;
coef=gain(k);
end
k=k+1;
end
O == coef * I;
end
And when I try to build library with ssc_build I get message like this:
Illegal flow control construct 'while' in equation block
Am I doing something wrong, or there is no possibility in simscape language to use "while" and "for" statements (although conditional "if" is allowed)?
Thanks in advance.

Respuesta aceptada

Arnaud Miege
Arnaud Miege el 7 de Jun. de 2011
while and for loops are not allowed in the Simscape language, see the equations documentation ("Supported Functions" section) and Defining Component Equations in the Simscape documentation. What are you trying to do?
Arnaud
  5 comentarios
Arnaud Miege
Arnaud Miege el 8 de Jun. de 2011
I would suggest doing this in Simulink/Stateflow or Embedded MATLAB and using a Simulink->PS Converter block to feed to the flow rate sources. Alternatively, if you want to stay within the Simscape environment, you could probably use the PS Switch block in conjunction with the PS Max and PS Min blocks.
Andreas
Andreas el 6 de Nov. de 2015
Hi Arnaud,
while and for would be helpful, to create parameter-driven discretisations of simscape-blocks (like in Modelica language) for any type of lumped models.

Iniciar sesión para comentar.

Más respuestas (1)

Vishnu Teja Vithala
Vishnu Teja Vithala el 9 de Jul. de 2018
I agree, Simscape not supporting while and for loops is pretty big limitation

Categorías

Más información sobre Composite Components en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by