フィルターのクリア

Finding an element in table without using if_else condition

1 回表示 (過去 30 日間)
Shrinish Donde
Shrinish Donde 2022 年 8 月 1 日
コメント済み: Shrinish Donde 2022 年 8 月 1 日
% Input
A = ["I";"I";"R"];
B = [1;1;0];
C = [1;0;2];
D = [0;2;2];
E = ["R";"S";"I"];
% Create Table
Table_A = table(A,B, C, D,E);
% The output E depends on the inputs ( A,B,C and D ). For eg.
% Only if ( A = "I" & B = 1 & C = 0 & D = 0 ), E = "R"
Question: I want to get the corresponding element in E without using an if else condition since there are a lot more elements and therefore a lot more conditions for getting each element in E.
Thank you.

採用された回答

Benjamin Thompson
Benjamin Thompson 2022 年 8 月 1 日
You can do some operations on the Table variables to get index vectors:
>> Table_A.A
ans =
3×1 string array
"I"
"I"
"R"
>> Table_A.A == "I"
ans =
3×1 logical array
1
1
0
Then use the index vectors to calculate the values for E, then copy the new values for E into the table.
  1 件のコメント
Shrinish Donde
Shrinish Donde 2022 年 8 月 1 日
Thanks Benjamin. Simpler than I thought !
/Shrinish

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by