Matlab Function Block reading erroneous values
1 view (last 30 days)
Show older comments
Hello, I have the following problem with this block.
The code it's very simple:
function y = fcn(u,p) %#codegen
persistent f if isempty(f) f = 0; end
if p>90 f=1; y=0; else y=0; end
if f==1
if p>60
y=u;
end
if p<60
y=0;
f=0;
end
else
y=0;
end
It has to wait until input (p) value is 90 to start doing the second if (where whatch that the value is higer than 60 or not.
p input is connected with a pressure sensor that starts from 60bar. The problem is that if I stop the simulation at the begining, p=148 or a higger value, and then it receives other aleatory values. Only if I wait to a long simulation, it starts (at 400seconds) to receives the true values that I can see on a scope.
I will be very grateful with any possible solution, thanks
0 Comments
Answers (1)
David Sanchez
on 1 Aug 2013
f changes value when p>90 and y=0 whatever happens to p, then, you go through a nested condition:
if f==1
if p>60
....
end
if p<60
...
but p>90.the second nested condition never applies.
Your function looks a bit incoherent. You should revise it carefully (sometimes a pen and paper approach helps a lot in following what your code will do).
0 Comments
See Also
Categories
Find more on Simulink 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!