Fast way to replicate array
조회 수: 3 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Mohammad Abouali
2015년 4월 28일
편집: Mohammad Abouali
2015년 4월 28일
w=[1 2; ...
3 4; ...
5 6];
N=5;
E=size(w,1);
F=size(w,2);
D=repmat(reshape(w',1,F,1,E),N,1,N,1);
댓글 수: 0
추가 답변 (2개)
Andrei Bobrov
2015년 4월 28일
편집: Andrei Bobrov
2015년 4월 28일
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]);
댓글 수: 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!