I'm very new to Matlab Simulink and I'm trying to implement a loop in the Matlab Function Block that goes on non-stop during the whole simulation. Input:
"t" from a simple clock to make it go on until the simulation lasts.
"v" and "i" what gives a specific "p*" value, by changing the ouptut "D" a little bit I want to check if this "p*" value gets bigger or smaller (in the whole model "v" and "i" are influenced by "D")
function D = fcn(v,i,t)
%#codegen
p1 = v*i;
D = 0.5;
D = D + 0.05;
while t > 0
p2 = v*i;
if p1 > p2
D = D - 0.05;
else
D = D + 0.05;
end;
p1 = p2;
end;
The Function Block says it is correct, but as I start to run it, it freezes. The next step I wanted to do (but never got there) is to put a little timer in it, to execute this loop lets say every 0.01 sec or something. Is that compliable with a Matlab Function Block or is there any way achieving this?
If-action subsystem
block and theWhile iterator subsystem
blocks? They are very convenient to use. – Robert Seifert