필터 지우기
필터 지우기

Matlab Function Block reading erroneous values

조회 수: 3 (최근 30일)
Alain
Alain 2013년 8월 1일
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

답변 (1개)

David Sanchez
David Sanchez 2013년 8월 1일
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).

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by