Access cell array inside another cell array

조회 수: 18 (최근 30일)
Rocio
Rocio 2014년 2월 4일
댓글: Kelly Kearney 2014년 2월 4일
Hello,
I have a 50x1 cell array. Each cell is a 2x1 array.
A = {2x1 cell;
2x1 cell;
2x1 cell
etc}
if I get into every cell I have cell = {a b}
I am trying to access each string in the 2x1 cell for all rows (a and b).
So if my array is called A this is the function I am using to extract the each column of the inside cell for all rows:
A = cellfun(@(x) x{:,1}{:,1}, A, 'UniformOutput',0)
B = cellfun(@(x) x{:,1}{:,2}, A, 'UniformOutput',0)
I am getting the following error: "Cell contents reference from a non-cell array object".
I was wondering if anyone can help me accessing those two columns of my multiindex cell array.
Thank you very much
  댓글 수: 2
Patrik Ek
Patrik Ek 2014년 2월 4일
Have you tried ordinary parenthesis second level?
Rocio
Rocio 2014년 2월 4일
Yes, and it returns only the second element on the first string

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

채택된 답변

Kelly Kearney
Kelly Kearney 2014년 2월 4일
The anonymous function used in cellfun is applied to each element of A, so the input it expects in your case would be a 1 x 2 cell of strings, not the parent cell array of cell arrays:
a = cellfun(@(x) x{1}, A, 'uni', 0);
b = cellfun(@(x) x{2}, A, 'uni', 0);
  댓글 수: 2
Rocio
Rocio 2014년 2월 4일
It works for a but for b I get the error Index exceeds matrix dimensions
Kelly Kearney
Kelly Kearney 2014년 2월 4일
Either a) one of the internal cell arrays wasn't a 2 x 1 cell array, or b) you save that first output as A (as in your example above), thus replacing your original A.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by