Sum two arrays using logical indices
2 次查看(过去 30 天)
显示 更早的评论
I want to sum two arrays
a = [ 1 2 3];
b = [2 3 1 ];
a_logical = [0 1 0];
a_logical = ~a_logical;
b_logical = [1 0 0];
b_logical = ~b_logical;
I want the sum of a + b to be
[ 1 0 3] + [0 3 1] = [1 3 4]
Any suggestion on how the above sum can be obtained using the logical indices stored in a_logical and b_logical?
1 个评论
采纳的回答
KALYAN ACHARJYA
2019-12-5
编辑:KALYAN ACHARJYA
2019-12-5
c=a.*(a_logical)+b.*(b_logical)
c =
1 3 4
0 个评论
更多回答(1 个)
JESUS DAVID ARIZA ROYETH
2019-12-5
Could it be that way? :
a (or (a_logical, b_logical)) + b (or (a_logical, b_logical))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!