필터 지우기
필터 지우기

How can I make a vector from the elements in the same position across many matrices?

조회 수: 1 (최근 30일)
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!

채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 30일
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by