フィルターのクリア

Two kind of instructions for specific blocks

2 ビュー (過去 30 日間)
Rene Sebena
Rene Sebena 2016 年 9 月 28 日
コメント済み: Rene Sebena 2016 年 9 月 28 日
Hi there, I am new in matlab and trying to solve this task. I have 20 experimental blocks and what I need to do is to display different instruction for different blocks
so that if B == [1,2,5,6,9,10,13,14,17,18]; display instruction A; and if B== [3,4,7,8,11,12,15,16,19,20]; display instruction B;
Can you reccommend me a command or help me how to solve this? Thank you very much.

採用された回答

Massimo Zanetti
Massimo Zanetti 2016 年 9 月 28 日
編集済み: Massimo Zanetti 2016 年 9 月 28 日
Very simple. Assume your block (vector) to test is X:
caseA=[1,2,5,6,9,10,13,14,17,18];
caseB= [3,4,7,8,11,12,15,16,19,20];
if isequal(X,caseA)
disp('option A');
elseif isequal(X,caseB)
disp('option B');
else
disp('no options available');
end
Whereas, if X is just a number and you want to test if it is in caseA or caseB do this:
caseA=[1,2,5,6,9,10,13,14,17,18];
caseB= [3,4,7,8,11,12,15,16,19,20];
if ismember(X,caseA)
disp('option A');
elseif ismember(X,caseB)
disp('option B');
else
disp('no options available');
end
  1 件のコメント
Rene Sebena
Rene Sebena 2016 年 9 月 28 日
Cool! Thank you very much, it works fine.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMath Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by