Sum two arrays using logical indices

3 vues (au cours des 30 derniers jours)
Deepa Maheshvare
Deepa Maheshvare le 5 Déc 2019
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 commentaire
KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Déc 2019
Can you elaborate more?
>> [ 1 0 3] + [0 3 1]
ans =
1 3 4

Connectez-vous pour commenter.

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 5 Déc 2019
c=a.*(a_logical)+b.*(b_logical)
c =
1 3 4

Plus de réponses (1)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH le 5 Déc 2019
Could it be that way? :
a (or (a_logical, b_logical)) + b (or (a_logical, b_logical))

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by