Effacer les filtres
Effacer les filtres

Finding an element in table without using if_else condition

1 vue (au cours des 30 derniers jours)
Shrinish Donde
Shrinish Donde le 1 Août 2022
Commenté : Shrinish Donde le 1 Août 2022
% 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.

Réponse acceptée

Benjamin Thompson
Benjamin Thompson le 1 Août 2022
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 commentaire
Shrinish Donde
Shrinish Donde le 1 Août 2022
Thanks Benjamin. Simpler than I thought !
/Shrinish

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by