Fast way to replicate array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Thang Bui
el 28 de Abr. de 2015
Editada: Andrei Bobrov
el 28 de Abr. de 2015
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 comentarios
Respuesta aceptada
Mohammad Abouali
el 28 de Abr. de 2015
Editada: Mohammad Abouali
el 28 de Abr. de 2015
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 comentarios
Más respuestas (2)
Andrei Bobrov
el 28 de Abr. de 2015
Editada: Andrei Bobrov
el 28 de Abr. de 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]);
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!