Azzera filtri
Azzera filtri

SImple question about Simulink S function

1 visualizzazione (ultimi 30 giorni)
Hello all
How in S function I can obtain:
U(t2) is the velocity at current time step and U(t1) is the velcity at previous time step
Please guide
  1 Commento
Sameer il 18 Giu 2014
Basically objective is to obtain the step size used during the particular iteration. Please guide!!!

Accedi per commentare.

Risposta accettata

Kaustubha Govind
Kaustubha Govind il 19 Giu 2014
You can use block.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.
  3 Commenti
Kaustubha Govind
Kaustubha Govind il 20 Giu 2014
Type msfcndemo_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.
Sameer il 21 Giu 2014
Modificato: Sameer il 21 Giu 2014
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)
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
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)
block.SimStateCompliance = 'DefaultSimState';
%%Run accelerator on TLC
%%Register methods
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('InitializeConditions', @InitConditions);
block.RegBlockMethod('Outputs', @Output);
%block.RegBlockMethod('Update', @Update);
function DoPostPropSetup(block)
%%Setup Dwork
block.NumDworks = 2;
block.Dwork(1).Name = 'Intial';
block.Dwork(1).Dimensions = 3;
block.Dwork(1).DatatypeID = 0;
block.Dwork(1).Complexity = 'Real';
block.Dwork(1).UsedAsDiscState = true;
block.Dwork(2).Name = 'time';
block.Dwork(2).Dimensions = 1;
block.Dwork(2).DatatypeID = 0;
block.Dwork(2).Complexity = 'Real';
block.Dwork(2).UsedAsDiscState = true;
function InitConditions(block)
%%Initialize Dwork
block.Dwork(1).Data = block.DialogPrm(2).Data;
function SetInpPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di;
block.OutputPort(1).Dimensions = di*4;
function Output(block)
[F]=fsolve(@(X) hope(X,block.Dwork(1).Data,TD,10),X);
block.OutputPort(1).Data =F;
%function Update(block)
block.Dwork(2).Data = block.CurrentTime;
where hope is a function returning the 4 equations.
Hope to get further guidance.

Accedi per commentare.

Più risposte (0)


Scopri di più su General Applications in Help Center e File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by