Clear Filters
Clear Filters

Indexing 3D Cell Array

67 views (last 30 days)
Jessica Kendall-Bar
Jessica Kendall-Bar on 28 Jun 2018
Commented: Guillaume on 28 Jun 2018
I have a 3D cell array with 1x58 cells (containing 58 cells of variable row numbers, but consistently 14 columns "N x 14 double"). When I try to index the first row and first column on the first page of the array, A{1,1,1} or A{:,1,1} or A{:,:,1}, I keep getting the same output, showing me the entire 2D array stored in the first "page" of the array.
How can I index only the first column of the first page of the array, for example?
Thank you in advance for your assistance.
  2 Comments
Guillaume
Guillaume on 28 Jun 2018
Edited: Guillaume on 28 Jun 2018
Your description is a bit confusing. Is the cell array 3D or 1x58? Is the content of each cell 1x58 or with multiple rows? Maybe, it is a 3D cell array (what size?) where each cell itself contains a 1x58 cell array and where each cell of that sub-cell array is a Nx14 matrix.
To clarify, what is the output
class(A)
size(A)
class(A{1})
size(A{1})
class(A{1}{1})
size(A{1}{1})
Note that some of these lines may produce an error if the structure is not as I assumed.
Guillaume
Guillaume on 28 Jun 2018
Also note, if A is indeed a 3D cell array, then
A{1, 1, 1} %same as A{1}
will return the first element of the cell array
A{:, 1, 1}
will return a comma separated list of the elements of the 1st column of the first page of the cell array. This will have very limited use to a matlab beginner.
A{:, :, 1}
will return a bigger comma separated list of the elements of the 1st page of the cell array. Again, usually not very useful for beginners.

Sign in to comment.

Answers (2)

Prabodh Katti
Prabodh Katti on 28 Jun 2018
Instead of using curly braces, use parentheses for indexing i.e A(1,1,1) instead of A{1,1,1}. So the fist column of the first page might be A(:,1,1). Curly braces access the content of the cell, which might be a char, a double or even a cell, whereas parentheses will index the subset which will also be a cell array. Refer: https://in.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html
I don't know how you are getting an entire page by A{1,1,1}. I tried this by creating a random 3D cell array and got only one element. Nevertheless do try using parantheses. If you have the entire column in double format and need to convert it to array of doubles, use cell2mat.

Sri Harish G
Sri Harish G on 28 Jun 2018
Since every page contains a matrix of type double,
to Index all elements in the first column of first page, You can use A{1}(:,1)
In general to index element in page number p, row number r and column number c, you can use A{p}(r,c)
  1 Comment
Guillaume
Guillaume on 28 Jun 2018
Calling p a page in A{p}(r, c) would be very misleading. You're mixing up indexing of the container and the containee. If you're using 1d indexing on the container A that would be because it is a row or column vector, hence does not have pages. Similarly, the containee matrix indexed with (r, c) would be 2D, again not having pages.

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!