How to define parameters in Simulink ?

1 回表示 (過去 30 日間)
Suppenhuhn
Suppenhuhn 2011 年 4 月 4 日
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.

採用された回答

MarkB
MarkB 2011 年 4 月 4 日
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 件のコメント
Kaustubha Govind
Kaustubha Govind 2011 年 4 月 4 日
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 2011 年 4 月 4 日
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 !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by