Effacer les filtres
Effacer les filtres

multiplying a 1xM vector by a KxN matrix

4 vues (au cours des 30 derniers jours)
Mnr
Mnr le 9 Nov 2015
Modifié(e) : Stephen23 le 9 Nov 2015
Hello there,
I have a 1xM vector, say V=[1 -1]; I would like to multiply it by a KxN matrix, say S=[0 0 1 1;1 1 0 0;1 0 1 0;0 1 0 1] such that at the beginning the first element of V gets multiplied by the first columns of S, then the second element of V be multiplied by the first columns of S, then the first element of V gets multiplied by the second column of of S, followed by the multiplication of the second element of V by the second column of S, and so forth. That is for the example mentioned above I get: [0 0 0 0 1 -1 1 -1;1 -1 1 -1 0 0 0 0;1 -1 0 0 1 -1 0 0;0 0 1 -1 0 01 -1]. I would appreciate if somebody can help me please. Thank you!

Réponse acceptée

Stephen23
Stephen23 le 9 Nov 2015
Modifié(e) : Stephen23 le 9 Nov 2015
Use bsxfun, reshape, and permute:
>> V = [1,-1]
V =
1 -1
>> S = [0,0,1,1; 1,1,0,0; 1,0,1,0; 0,1,0,1]
S =
0 0 1 1
1 1 0 0
1 0 1 0
0 1 0 1
>> X = bsxfun(@times,S,reshape(V,1,1,[]));
>> reshape(permute(X,[3,2,1]),[],size(S,1)).'
ans =
0 0 0 0 1 -1 1 -1
1 -1 1 -1 0 0 0 0
1 -1 0 0 1 -1 0 0
0 0 1 -1 0 0 1 -1

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by