How to perform repmat function to repeat rows of a matrix
Mostrar comentarios más antiguos
A=[1,0,0,0,1;2,0,0,0,2;3,0,0,0,3]
I would like to repeat each row for n times and get output something like this when n is 2:
output=[1,0,0,0,1;1,0,0,0,1;2,0,0,0,2;2,0,0,0,2;3,0,0,0,3;3,0,0,0,3]
Respuesta aceptada
Más respuestas (5)
B = repelem(A,2,1)
2 comentarios
Zee
el 19 de Ag. de 2022
A = [1,0,0,0,1;2,0,0,0,2;3,0,0,0,3];
n = 2;
B = [];
for i = 1:size(A,1)
B = [B;repmat(A(i,:),n,1)];
end
B
A=[1,0,0,0,1;2,0,0,0,2;3,0,0,0,3]
reshape(repmat(reshape(A,1,1,[]),2,1,1),[],size(A,2))
Bruno Luong
el 19 de Ag. de 2022
n = 2;
A(ceil((1:n*end)/n),:)
Bruno Luong
el 19 de Ag. de 2022
n = 2;
A(kron(1:end,ones(1,n)),:)
Bruno Luong
el 19 de Ag. de 2022
n = 2;
kron(A,ones(n,1))
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!