Weird issue from a simulink model (a simple sfunction block in series to a switch) Could it be a bug on Matlab 7.8 (2009a) ?
Mostra commenti meno recenti
Hello everyone,
I created a model with simulink composed by a c-mex sfunction block and an upstream switch connected to the sfunction input. The C sfunction has two input: IV IN, one output, Y and one discrete state variable. This switch is supposed to give the initial value of the state variable x of the sfunction block during the execution of the mdlInitialize. The output of the sfuction, y, is simply the state variable x. The update of the sfunction is just x=IN
So here it is a sketch of the code:
Init
x=IV
Output
y=x
Update
x=IN
As inputs of the switch I put three constant c1, c2 and c3. The condition on the switch is to pass the first input if c2>0.
I chose this value
c1=1
c2=1
c3=2
in this way the output of the switch is 1, so IV equals to 1 And I chose IT constantly equals to 1
After several simulations, performed on both a variable step time solver and a fixed step one (runge-kutta), the output of the sfunction has a stunning behavior at the beginning, it's equal to zero, instead to be equal to 1
even if all the "scope"/"display" blocks and all the debugging tests performed (by Visual C) shows the IV variable is equal to 1 from the beginning.
Even if I replace the switch with a gain block, I have the same behavior. The only way to have the logical and excepted behavior is to directly connect a constant block to the sfunction
is that a bug in Matlab?
Actually I sorted out by making a switch using a sfunction with an init stage, but this outcome is still bizarre and puzzling
I use Matlab 7.8 (2009a)
thanks 4 reading
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su General Applications in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!