フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by