How to define parameters in Simulink ?

1 view (last 30 days)
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.

Accepted Answer

MarkB
MarkB on 4 Apr 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 Comments
Kaustubha Govind
Kaustubha Govind on 4 Apr 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 on 4 Apr 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 !

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!