Repeat elements of a vector as matrixes in a multidimensional array.
Mostrar comentarios más antiguos
Hello Everyone.
I want to repeat elements of a vector as matrixes in a multidimensional array. For example, say I have the vector v = [1 2 3 4 5]. Then I want to construct a three dimensional array w of dimension say 4*3*lenght(v) where: w(:,:,1) = v(1), w(:,:,2) = v(2), ... w(:,:,length(v)) = v(end). Is there a way to do this without using a for loop ? Any help would be precious.
Thank you.
Respuesta aceptada
Más respuestas (1)
James Tursa
el 2 de Dic. de 2019
Another way:
m = size of 1st dimension
n = size of 2nd dimension
v = your row vector
result = reshape(repmat(v,m*n,1),m,n,[]);
1 comentario
Idossou Marius Adom
el 2 de Dic. de 2019
Categorías
Más información sobre MATLAB 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!