Finding an element in table without using if_else condition

1 次查看(过去 30 天)
% 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
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by