How can I make a vector from the elements in the same position across many matrices?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
sixwwwwww
on 30 Oct 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 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!