Borrar filtros
Borrar filtros

S-function conditions

2 visualizaciones (últimos 30 días)
Marven Jabian
Marven Jabian el 21 de Oct. de 2011
Respondida: haMed el 10 de Oct. de 2014
Hi everyone!
I am new in s-function implementation in Simulink.
from:
dx/dt = Ax + Bu; Y = Cx + Du;
Where you can initialize A, B, C, and D to some value. For next sample time, I would like to change the values of A, B, C, and D. Is there any way to implement the code of it using level 1 s-function?
Sample:
if t >= 1e-5 && u(5)>0
A = [1 2 3 4;4 5 3 1;4 5 3 2;3 4 1 0]; B = [3; 4; 5; 6]; C = [1 2 3 4;4 5 6 1;4 6 3 2;3 6 1 3]; D = [0;0;1;0];
else
A = eye(4); B = zero(4,1); C = eye(4); D = zero(4,1);
end
where should I Implement this type of code?
Also, how can I declare a global variable so that it can be updated at any value of flag.
Thanks!

Respuesta aceptada

Omur
Omur el 21 de Nov. de 2011
Two options: 1. Take A,B,C, D as inputs. Since Level-1 S-functions have a single input port, this requires painful reshape-mux-index-reshape sequences. 2. If A,B,C,D are dependent on time and you know how, then define them as a function of time in the main function (that is, first thing after the function definition, before you call any subfunctions.)
You can define a persistent variable at the main function.
  2 comentarios
Marven Jabian
Marven Jabian el 22 de Dic. de 2011
How can I implement the Option 1? Can you give me some hints or any links that might help?
Thanks!
Marven Jabian
Marven Jabian el 22 de Dic. de 2011
I got it now! Thanks!

Iniciar sesión para comentar.

Más respuestas (1)

haMed
haMed el 10 de Oct. de 2014
I prefer to use stateflow in this issue.

Categorías

Más información sobre Simulink Functions 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