Fast way to replicate array
Show older comments
I have a matrix W of size ExF, and I have a matrix D of size NxFxNxE where D(n,:,n,:) = W'
Is there a fast way to replicate W to form D without having to loop through N
Thanks!
Accepted Answer
More Answers (2)
Andrei Bobrov
on 28 Apr 2015
Edited: Andrei Bobrov
on 28 Apr 2015
i1 = bsxfun(@plus,[0;N]+1,(0:N-1)*(2*N+1));
i2 = bsxfun(@plus,i1,reshape((0:F)*i1(end),1,1,[]));
D = zeros(N,F,N,E);
D(i2) = permute(repmat(W,[1,1,N]),[2,3,1]);
Categories
Find more on Resizing and Reshaping 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!