Trying to index into a cell array using columns of a matrix

5 ビュー (過去 30 日間)
Michael Bochert
Michael Bochert 2023 年 9 月 13 日
コメント済み: Dyuman Joshi 2023 年 9 月 13 日
I am trying to use two columns in a matrix to index into a cell array.
I am trying to use the 2nd column of the matrix to index into the first layer of the cell array, and the 1st column to index into the 2nd layer of the cell array.
For example, if a given row in the two-column matrix looks like this:
[2 1] ---- ("2" corresponds to the value in the first column, "1" corresponds to the value in the 2nd column)
I want to index into the cell array as such:
Cell_array{1}{2}
I want to index into the cell array using every single row of the two-column matrix. Every time these values match, I want to extract the data from the cell array.
Any help would be appreciated! Thank you. I hope this makes sense..
  3 件のコメント
Michael Bochert
Michael Bochert 2023 年 9 月 13 日
I have been able to index into it using curly braces twice.. Here is the .mat file :)
Thx for your help!
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 13 日
"Matlab doesn't support such syntax as Cell_array{1}{2}"
@dpb, It does -
C = {{1 [2 3]}}
C = 1×1 cell array
{1×2 cell}
C{1}{2}
ans = 1×2
2 3

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 9 月 13 日
編集済み: Matt J 2023 年 9 月 13 日
I am trying to use two columns in a matrix
Call this matrix I.
to index into a cell array.
Call it C.
Then you could do,
arrayfun(@(i,j) C{j}{i}, I(:,1), I(:,2),'uni',0)
  1 件のコメント
Michael Bochert
Michael Bochert 2023 年 9 月 13 日
Beautiful!! Worked like a charm. :)
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by