3d Matrix - Extract Subarray and Multiply by Conjugate Transpose without Forloops
古いコメントを表示
I have a 3d matrix A(i,j,k) of size [1:100,1:10000,1:989]. On the kth index I want to extract the 989 elements into a vector u and form the product u*ctranspose(u), for each of the
indices.
Using a double for loop, which is not something one should do in Matlab,
% this is an evil double for loop - I want to avoid doing this.
for ii=1:100
for jj=1:10000
u=squeeze(A(ii,jj,:));
% somehow compute and store uu in a vectorized way, but how?
uu=u*ctranspose(u); % note that uu is a 989x989 matrix, not a vector.
end %ii
end %jj
This would be really slow. Is there a vectorized way to the above, so I am not doing a double for loop?
17 件のコメント
Yes, but the result will consume 7 TB in double floats
989^2*10000*100*8/2^40
Outer-products are a bad idea for many other reasons, too. What are you going to do with this even if you could store it?
Science Machine
2022 年 9 月 6 日
Matt J
2022 年 9 月 6 日
70 GB still seems like a lot. Do you have that much RAM?
Science Machine
2022 年 9 月 7 日
Bruno Luong
2022 年 9 月 7 日
What a waste of memory (and cpu) to explicitly expand rank-1 matrices.
Science Machine
2022 年 9 月 7 日
Bruno Luong
2022 年 9 月 7 日
Of course yours
Science Machine
2022 年 9 月 7 日
@Science Machine The connection between xcorr and what you're attempting is not as apparent as you seem to think. A rank-1 matrix doesn't represent a correlation operation.
Science Machine
2022 年 9 月 7 日
Matt J
2022 年 9 月 7 日
It was not clear what @Bruno Luong meant - does he think it's okay to modify a single step of a procedure? And what is his alternative.
That depends on what you plan to do with uu. Note for example that if you have column vectors u and x, then this,
y=u*(u'*x);
produces the same result as this,
y=(u*u')*x;
but the former is much more efficient, both in terms of memory consumption and CPU time.
Science Machine
2022 年 9 月 7 日
Science Machine
2022 年 9 月 8 日
編集済み: Science Machine
2022 年 9 月 8 日
Matt J
2022 年 9 月 8 日
Probably, but you haven't explained what t and r are.
Science Machine
2022 年 9 月 8 日
編集済み: Science Machine
2022 年 9 月 8 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Correlation and Convolution についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!