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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!