How to use an if else statement to choose one specific variable?

2 ビュー (過去 30 日間)
Joana
Joana 2018 年 12 月 2 日
コメント済み: madhan ravi 2018 年 12 月 2 日
Hi
I have a variable 'tf', in the form of 1s and 0s.
tf= [1 0 0 0 1 1 0 1 1];
Now there is this 2nd variable which is tf2, as:
tf2=[12 15 16 17 18 19 20 30 48];
I wan to do is, if tf==1, save the corresponding value of variavle tf2 in X, and when tf==0, save the corresponding values in the variable Y. by using the for loop and if else.
e.g for tf==1; X=[12 18 19 30 48]; and Y=[1516 17 20];
How i can do this in MATLAB. Any help will be appreciated. :)
  1 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 2 日
Don‘t close the question that have an answer.

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 12 月 2 日
X = tf2(tf==1);
Y = tf2(tf==0);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by