Filter löschen
Filter löschen

Indexing 3D Cell Array

67 Ansichten (letzte 30 Tage)
Jessica Kendall-Bar
Jessica Kendall-Bar am 28 Jun. 2018
Kommentiert: Guillaume am 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 Kommentare
Guillaume
Guillaume am 28 Jun. 2018
Bearbeitet: Guillaume am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Prabodh Katti
Prabodh Katti am 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 am 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 Kommentar
Guillaume
Guillaume am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by