Finding an element in table without using if_else condition

1 visualizzazione (ultimi 30 giorni)
% 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.

Risposta accettata

Benjamin Thompson
Benjamin Thompson il 1 Ago 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.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by