Is there a better to multiply matrices with is pattern?

1 vue (au cours des 30 derniers jours)
John
John le 9 Mar 2013
I have a 2 x 2 matrix A = [1 2; 3 4] and a 100 x 1 column vector B = [1 2 3 4 5 6 . . . 100]' and I want to multiply matrix A with each 2x1 sub-vector of B.
For example : [1 2; 3 4] * [1 2]
[1 2; 3 4] * [3 4]
[1 2; 3 4] * [5 6]
.
.
.
[1 2; 3 4] * [99 100]
How can I do this efficiently in code and store the results into one column vector?
  1 commentaire
the cyclist
the cyclist le 9 Mar 2013
What shape do you want the final result to be? 100x1? 2x50?

Connectez-vous pour commenter.

Réponse acceptée

Cedric
Cedric le 9 Mar 2013
Just
C = A * reshape(B, 2, []) ;
will produce a 2x50 C matrix whose columns are the 50 solutions.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 9 Mar 2013
Modifié(e) : Azzi Abdelmalek le 9 Mar 2013
Example
A=rand(2)
B=rand(1000,1)
B=reshape(B,2,[])
out=arrayfun(@(x) A*B(:,x),1:size(B,2),'un',0)
% You can get the result as one matrix
out=cell2mpat(out)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by