How can I make a vector from the elements in the same position across many matrices?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Patrick
el 30 de Oct. de 2013
Respondida: sixwwwwww
el 30 de Oct. de 2013
I have 736 matrices of size 72x144. I want to find a vector of 736x1, where each element of the new vector represents the element from the same position in each of the original matrices.
For example:
A = [ 1 2 3 | 4 5 6 | 7 8 9 ]
B = [ 2 2 2 | 3 3 3 | 4 4 4 ]
C = [ 5 4 3 | 1 2 3 | 5 6 7 ]
Want:
D4 (position 2,1) = [ 4 3 1 ]
D5 (position 3,2) = [ 8 4 6 ]
What is the easiest way for me to do this? I can do it manually, but it will take me all weekend. Please help!
0 comentarios
Respuesta aceptada
sixwwwwww
el 30 de Oct. de 2013
Dear Patrick, you can do it as follows:
NumberOfMatrices = 736;
A = randi(100, 72, 144, NumberOfMatrices); % Your 736 matrices
for i = 1:NumberOfMatrices
B{i} = reshape(A(:,:,i)', 1, []);
end
C = reshape((cell2mat(B)), [], NumberOfMatrices); % Each row of C represent one vector of length 736 from corresponding values from 736 matices
I hope it helps. Good luck!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!