フィルターのクリア

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 Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by