フィルターのクリア

How schould the matlab function be to hold an signal between two values?

4 ビュー (過去 30 日間)
AF
AF 2022 年 10 月 7 日
コメント済み: AF 2022 年 10 月 7 日
I have a rising signal of a temperature. As long as the value has not reached a limit, e.g. 90%, "0" is to be displayed. If the value is reached, 1 is displayed. After that, the value can drop to e.g. 30% until "0" is output again. This is to achieve that the value remains between the two limits by the output of 0 and 1.
It is about a Simulink model and the code for it should be in a matlab-fct block.
I tried a lot with if-functions but i dont get it.

採用された回答

Les Beckham
Les Beckham 2022 年 10 月 7 日
編集済み: Les Beckham 2022 年 10 月 7 日
Perhaps something like this in a MATLAB Function block?
function out = determineStatus(in)
persistent out
if isempty(out)
out = 0; % initial output value
end
% implement the hysteresis
if out = 0 && in > 90
out = 1;
elseif out = 1 && in < 30
out = 0;
end
end
  4 件のコメント
Les Beckham
Les Beckham 2022 年 10 月 7 日
編集済み: Les Beckham 2022 年 10 月 7 日
Of course you are right (== instead of =). Thanks for pointing that out. I thought about true/false vs. 1/0 but since OP specifically asked for 0 and 1, I went with that.
Also, good call on the relay block. I knew there was a simpler way to do this with a built-in block but I don't currently have Simulink to browse through the library.
Then feed B/A into the function and change 90 and 30 to 0.9 and 0.3.
AF
AF 2022 年 10 月 7 日
Thanks @Les Beckham,
it's working.

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 10 月 7 日
The Relay block does exactly that.

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by