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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by