factorial using level 2 s-function
1 view (last 30 days)
Show older comments
hi, i am writing a code to find a factorial using level 2 s-function. the main thing is to learn about the discrete states. i am beginner in a s function. when i run the code in the simulink with constant block and display block as input and output. iam getting '0' as output.
can anyone tell me what i am doing wrong within this code. and suggest me some reference material to learn about s-function to the beginner. all i find till now is whole bunch of codes. which i barely understand.
the code is,
function anil2sfun(block)
function setup(block)
block.numinputports = 1;
block.numoutputports = 1;
block.setprecompinpportinfotodynamic;
block.setprecompoutportinfotodynamic;
block.inputport(1).directfeedthrough = true;
block.regblockmethod('postpropagationsetup', @dopostpropsetup);
block.regblockmethod('outputs', @output);
block.regblockmethod('update', @update);
block.regblockmethod('initializeconditions', @initialconditions);
function dopostpropsetup(block)
block.numdworks = 1;
block.dwork(1).name = 'x0' ;
block.dwork(1).dimensions = 1;
block.dwork(1).datatyprID = 0;
block.dwork(1).complexity = 'real';
block.dwork(1).usedasdiscstate = true;
function output(block)
block.outputport(1).data= block.dwork(1).data * block.inputport(1).data ;
function update(block)
if block.dwork(1).data < block.inputport(1).data
block.dwork(1).data =block.dwork(1).data + 1;
end
function initialconditions(block)
block.dwork(1).data=1;
%block.dwork(1).data=block.dialogprm(1).data;
0 Comments
Answers (0)
See Also
Categories
Find more on Configure Block Features for MATLAB S-Functions 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!