Manipulate multidimensional matrix in for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Anna
el 3 de Mayo de 2017
Comentada: Andrei Bobrov
el 3 de Mayo de 2017
Hi, I have a matrix called multidim with 2x100x3 values. I would like to make this a 6x100 matrix by adding the matrix defined in each page under the previous one.
for i = 1:2
matrix = [multidim(:,:,i);multidim(:,:,i+1)];
end
This is what I have tried, but this only works if I have a 2x100x2 matrix. How do I make this a loop which remembers the previous created matrix and uses this in order to keep adding rows from the next page?
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 3 de Mayo de 2017
a = num2cell(multidim,[1,2]);
matrix = cat(1,a{:});
2 comentarios
Stephen23
el 3 de Mayo de 2017
Editada: Stephen23
el 3 de Mayo de 2017
Note my answer is just one line, does not waste memory with unnecessary variables in the workspace, and runs around twice as fast as this answer:
Elapsed time is 6.32136 seconds. % this answer
Elapsed time is 3.98123 seconds. % my answer
Ver también
Categorías
Más información sobre Matrix Indexing 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!