How to define parameters in Simulink ?

1 visualización (últimos 30 días)
Suppenhuhn
Suppenhuhn el 4 de Abr. de 2011
I have a problem with a Level-2 M-file in Simulink. In my Simulink-model the Level-2 M-file should function as a switch, depending on the parameter "T". "S" is the value of the only input to my function.
function Outputs(S)
if T==0
if S==1
T==1
end
elseif T==1
if S==1
T==0
end
end
block.OutputPort(1).Data = T;
(Well it´s maybe not so professionally written..) The parameter "T" should be a paramter , that has the value 0 at the start of my model. And it changes the value during each calculation-loop.
Now the simple problem: How can I set the value of "T" to zero at the start of my model ? If I´m writting T=0 in ModelProperties/Callbacks/InitFcn, I receive the error "Undefined function or variable 'T' in my M-file.

Respuesta aceptada

MarkB
MarkB el 4 de Abr. de 2011
You may want to make "T" a state variable using work vectors. Within Simulink, blocks aren't able to influence/alter/change their parameters, so the use case that you are describing wouldn't be allowed with the Simulink definition of "parameters".
  2 comentarios
Kaustubha Govind
Kaustubha Govind el 4 de Abr. de 2011
See here for help on using work vectors in Level-2 MATLAB S-functions: http://www.mathworks.com/help/toolbox/simulink/sfg/brd0tgs.html#brd2qpw
Also, note that the input to Outputs is the block handle itself (not the input 'S'). You need:
S = block.InputPort(1).Data;
Instead of 'T' use block.Dwork(1).Data (you need to configure dWork vectors in the PostPropagationSetup method also).
Suppenhuhn
Suppenhuhn el 4 de Abr. de 2011
Thanks so much !!
I really appreciate your hints on Dwork Vectors as I stumbled so often upon the problem of passing data within Simulink. Even though I first have to read (and understand) the help, I´m glad to have a straw to clutch at !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by