How to define parameters in Simulink ?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!