3d Matrix - Extract Subarray and Multiply by Conjugate Transpose without Forloops
4 views (last 30 days)
Show older comments
Science Machine on 6 Sep 2022
Edited: Science Machine on 8 Sep 2022
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.
% 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.
This would be really slow. Is there a vectorized way to the above, so I am not doing a double for loop?
Matt J on 7 Sep 2022
Edited: Matt J on 7 Sep 2022
UU = reshape(Ar,p,1,).*conj(reshape(Ar,1,p,));
UU=reshape(UU,p,p,m,n); %obtain the (i,j)-th outer product as UU(:,:,i,j)
More Answers (0)
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!