필터 지우기
필터 지우기

Indexing 3D Cell Array

조회 수: 67 (최근 30일)
Jessica Kendall-Bar
Jessica Kendall-Bar 2018년 6월 28일
댓글: Guillaume 2018년 6월 28일
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
Guillaume
Guillaume 2018년 6월 28일
편집: Guillaume 2018년 6월 28일
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 2018년 6월 28일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Prabodh Katti
Prabodh Katti 2018년 6월 28일
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 2018년 6월 28일
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
Guillaume
Guillaume 2018년 6월 28일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by