Is there a better to multiply matrices with is pattern?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cedric
2013년 3월 9일
Just
C = A * reshape(B, 2, []) ;
will produce a 2x50 C matrix whose columns are the 50 solutions.
댓글 수: 0
추가 답변 (1개)
Azzi Abdelmalek
2013년 3월 9일
편집: Azzi Abdelmalek
2013년 3월 9일
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!