Loop through Matrix, to create multiple matrices from every nth row
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mat
el 15 de Sept. de 2014
Comentada: Andrei Bobrov
el 15 de Sept. de 2014
Hi.
I have a very large matrix (1600x19). Call this matrix A.
I want to create new matrices from this, t(i), and save them as new matrices.
I want the first new matrix to be contructed from rows 1, 17, 33, 49 etc... so for this, by my reckoning, I would write t1=A(1:16:end,:). Then the next matrix to consist of row 2, 18, 34, 50 etc.. And so on.
I would like to create a loop that would create 16 matrices this way.
I have started with
while i<17
t(i)=A(i:16:end,:)
end
I'm aware this is lacking something, just don't know what!! Any help is much appreciated, especially if there's some explanation of the logic. New to looping :)
0 comentarios
Respuesta aceptada
Sean de Wolski
el 15 de Sept. de 2014
Editada: Sean de Wolski
el 15 de Sept. de 2014
What do you want to do with these matrices? Often, for this I would suggest crating a 16x19xp array where each slice in the third dimension is the sub arrays you want. Then you can work on those slices as necessary:
x = rand(1600,19);
x3d = permute(reshape(x.',19,[],16),[3 1 2]);
Will build the three d matrix. Now for the 17th "sub array"
x3d(:,:,17)
1 comentario
Andrei Bobrov
el 15 de Sept. de 2014
x3d = permute(reshape(x,16,[],19),[2,3,1]);
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping 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!