converting a matrix sequentially in to single column
8 visualizaciones (últimos 30 días)
TESFALEM ALDADA el 22 de Feb. de 2020
I have a matrix of 600*12, then the idea is:
- first to sequentially convert the first 1-30 row by 12 column in to single column.
- and the second matrix from 31-60 row by 12 column in to single column and to continue from the column in step 1.
- and this process extends to the end of 600 row
- So how can i write a for loop to do this
Más respuestas (1)
John D'Errico el 22 de Feb. de 2020
A = rand(600,12);
B = reshape(A,[30,20,12]);
B = permute(B,[1 3 2]);
B = reshape(B,[30*12,20]);
I created B there as the desired result, but I did it in three steps. The trick is to understand how the elements of an array are stored in memory, in what sequence.
I temporarily converted the array into a 3 dimensional array using reshape, then permute re-orders the elements as I needed. Finally, reshape converts the result into a 360x20 array. Each column of that result is as was desired.