Info

This question is closed. Reopen it to edit or answer.

Extracting 1 cell from a multiple matricies

2 views (last 30 days)
Robert
Robert on 11 Nov 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
I have 40 matricies, each 35x43. I want to make a series of columns each 8x5 where each value is the first cell from each of my 40 matrices (8 years of data 5 different types of data).
How can I do this? I'm pretty new to matlab so detail would be appreciated :)

Answers (1)

Image Analyst
Image Analyst on 11 Nov 2014
Assuming when you say "cell" you really mean "element" of a regular 2D matrix and not a cell of a cell array, then you can use linear indexing to get the first (upper left) element of each of your 40 matrices:
Output(1,1) = matrix1(1)
Output(2,1) = matrix2(1)
Output(3,1) = matrix3(1)
Output(4,1) = matrix4(1)
Output(5,1) = matrix5(1)
Output(6,1) = matrix6(1)
Output(7,1) = matrix7(1)
Output(8,1) = matrix8(1)
Output(1,2) = matrix9(1)
Output(2,2) = matrix10(1)
Output(3,2) = matrix11(1)
Output(4,2) = matrix12(1)
Output(5,2) = matrix13(1)
Output(6,2) = matrix14(1)
Output(7,2) = matrix15(1)
etc.
You could also use (1,1) instead of (1) if that's what you prefer - they're equivalent.
If that's not what you meant, then please read the FAQ to get your terminology accurate: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

Community Treasure Hunt

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

Start Hunting!