Effacer les filtres
Effacer les filtres

Vector and Matrix mutiplication

1 vue (au cours des 30 derniers jours)
Moe Joe
Moe Joe le 27 Nov 2016
Commenté : Star Strider le 27 Nov 2016
Hi there;
I have a vector A(kx1) and a matrix B (nxk). I need select rows from that correspond to ONES in A, and sum those rows mod2:
Example:
A =[1 0 1 0 1] and
B = [1 0 1 0 1;
1 0 0 1 0;
0 1 1 1 1;
1 1 0 1 1;
0 1 1 0 1];
In this example, I want to add rows that indicates ones in A, i.e. rows of B(1, 3,5) & sum those 3 rows mod2.
Kindly help.

Réponse acceptée

Star Strider
Star Strider le 27 Nov 2016
I’m not certain that I understand what you want to do.
See if this works:
A = [1 0 1 0 1];
B = [1 0 1 0 1; 1 0 0 1 0; 0 1 1 1 1; 1 1 0 1 1; 0 1 1 0 1];
C = B(logical(A'),:);
Out = mod(sum(C,2),2)
  4 commentaires
Moe Joe
Moe Joe le 27 Nov 2016
OK, let me rephrase my question in terms of a picture:
Star Strider
Star Strider le 27 Nov 2016
That clarifies things. You are actually summing the columns of ‘D’, so that would be ‘sum(D,1)’ (or more simply, ‘sum(D)’) rather than ‘sum(D,2)’ that would sum the rows.
So the desired result would be:
Out = mod(sum(D),2)
or in my code:
Out = mod(sum(C),2)
producing the result described by (5).

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by