Sum two arrays using logical indices

조회 수: 12 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2019년 12월 5일
편집: KALYAN ACHARJYA 2019년 12월 5일
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
KALYAN ACHARJYA 2019년 12월 5일
Can you elaborate more?
>> [ 1 0 3] + [0 3 1]
ans =
1 3 4

댓글을 달려면 로그인하십시오.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 5일
편집: KALYAN ACHARJYA 2019년 12월 5일
c=a.*(a_logical)+b.*(b_logical)
c =
1 3 4

추가 답변 (1개)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 12월 5일
Could it be that way? :
a (or (a_logical, b_logical)) + b (or (a_logical, b_logical))

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by