You can useblock.CurrentTime to get the current time in the S-function. You can use a DWork to store the current time at each step and use it in the next step to compute the difference.
Typemsfcndemo_sfundsc2 at your MATLAB prompt to see an example S-function that uses a DWork to store the previous input value. You will need two Dworks, one for the input and one for current-time.
Hello....Thank you for letting me know. I tried to write the s function though its running but I guess something is wrong in time,not sure though. Can you have a look and let me know whether I did it in the right manner or not.
function msfcn_equation_trans(block)
setup(block);
%endfunction
function setup(block)
block.NumDialogPrms = 2;
%%Register number of input and output ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
%%Setup functional port properties to dynamically
%%inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DirectFeedthrough = false;
%block.InputPort(2).DirectFeedthrough = false;
%%Set block sample time to inherited
block.SampleTimes = [-1 0];
%%Set the block simStateCompliance to default (i.e., same as a built-in block)
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.