Vectorizing a funky matrix multiplication

I have two matrices H and W, where H is Nx1873 and W is 262144xN (N is a small integer, usually 10-20). I multiply these matrices using the following code:
comp = zeros([512 512 1873 N]);
for i = 1:N
comp(:,:,:,i) = reshape(W(:,i)*H(i,:),[512 512 1873]);
end
Is there a way to vectorize this operation?

댓글 수: 1

Matt J
Matt J 2017년 6월 22일
If N is a small integer, vectorization will probably not make much difference.
Also, the operation itself seems like a bad idea. I don't know what you're planning to do with all of those outer products comp(:,:,:,i), but in most situations there are efficient ways to manipulate outer-products without computing them directly. They consume a lot of memory in spite of containing very little information.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2017년 6월 22일
편집: Matt J 2017년 6월 22일

0 개 추천

Wr=reshape(W,[],1,N);
Hr=reshape(H.',1,[],N);
comp=reshape( bsxfun(@times, Wr,Hr), 512,512,[]);

댓글 수: 2

Matt J
Matt J 2017년 6월 22일
If N is a small integer, vectorization will probably not make much difference.
Also, the operation itself seems like a bad idea. I don't know what you're planning to do with all of those outer products comp(:,:,:,i), but in most situations there are efficient ways to manipulate outer-products without computing them directly. They consume a lot of memory in spite of containing very little information.
I'm using H and W as outputs of either nnmf() or lsqnonneg(), and creating matrices that represent each of the N components individually for my original 512x512x1873 dataset. I use this to create movies where each component can be color coded, to aid in visualizing my data. I'm not sure how else I can organize the data, since I need to again matrix multiply it by my colormap as a final step, and visualize all components at once for each timepoint.
Thanks for your answer, I will try it ans see if there is any improvement!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2017년 6월 22일

댓글:

2017년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by