入力信号に0と1と無限大(inf)の3つの状態を持たせ条件判定に使いたいが。。。
7 views (last 30 days)
Show older comments
0の場合1の場合未入力(inf)の3つの条件で遷移先を決定させたいのですが、やり方が分からず行き詰まっております。
そもそも、無限大を条件に使う事は出来ないのでしょうか?
また、可能であれば解決策をご教示頂きたいです。
0 Comments
Accepted Answer
Hernia Baby
on 24 Feb 2021
Edited: Hernia Baby
on 24 Feb 2021
「0 or 1 or inf」で判定させたいときは logical と isinf関数 を使います。
判定だけなら、これが使いやすい気がします。
【例】logical値で抜き出す場合(何行目にそれがあるか)
idx = [0 0 1 inf 1 0 1 inf];
idx_0 = idx == 0; % 0の行を返す
idx_1 = idx == 1; % 1の行を返す
idx_inf = isinf(idx); % infの行を返す
入力信号が3種で命令を与えるなら、0か1かそれ以外で指示出すのもありかなと思います。
【例】vの要素が0,1,infとして繰り返し判定をさせます
i = 1;
while i <= length(v)
if v(i) == 0
% statements1
elseif v(i) == 1
% statements2
else
% statements3
end
i = i + 1;
end
0 Comments
More Answers (1)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!