フィルターのクリア

comparision of data with logic given as input

1 回表示 (過去 30 日間)
Sumanth
Sumanth 2023 年 2 月 27 日
編集済み: Walter Roberson 2023 年 2 月 28 日
This is a sample data for 3. I am stuck at how to write the same logic for 10 such that there should be comparision for all the input values given for T1 ,T2, .... T10.
I = zeros(1,3);
if T1 == T2
I(1,1)= 1;
I(1,1)= 0;
elseif T1 > T2
I(1,1)= 1;
I(1,2)= 0;
elseif T1 < T2
I(1,1)= 0;
I(1,2)= 1;
end
note: only one element in I should be equal to 1 in the end in such a way that the highest T gets the value 1 in I.

採用された回答

Voss
Voss 2023 年 2 月 27 日
編集済み: Voss 2023 年 2 月 27 日
Assuming T1, ..., T10 are scalars,
T = [T1 T2 T3 T4 T5 T6 T7 T8 T9 T10];
[~,idx] = max(T);
I = zeros(size(T));
I(idx) = 1;
  2 件のコメント
Sumanth
Sumanth 2023 年 2 月 28 日
Thank you so much! This works!
Voss
Voss 2023 年 2 月 28 日
You're welcome!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2023 年 2 月 27 日
Can you dynamically create and operate on variables with numbered names like T1, T2, T3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by