필터 지우기
필터 지우기

Accessing 1 by n array from a cell array

조회 수: 4 (최근 30일)
Aleem Andrew
Aleem Andrew 2020년 10월 12일
댓글: Star Strider 2020년 10월 12일
The output of the following code is the cell array poh. Is there a way to instead access the first subarray {'poh',3,4.56} through a similar command and commands to find, for example, its size?
a=[{'poh',3,4.56},{'v',5}]
a{1}

채택된 답변

Star Strider
Star Strider 2020년 10월 12일
편집: Star Strider 2020년 10월 12일
The problem is that the square brackets [] concatenate the two cells to produce:
a =
1×5 cell array
{'poh'} {[3.0000e+000]} {[4.5600e+000]} {'v'} {[5.0000e+000]}
If you replace them with curly braces {}, ‘a’ becomes:
a =
1×2 cell array
{1×3 cell} {1×2 cell}
and the result of
a{1}
is:
ans =
1×3 cell array
{'poh'} {[3.0000e+000]} {[4.5600e+000]}
as desired.
With that, you can then get:
Out = cellfun(@size, a, 'Uni',0)
Out{1}
Out{2}
producing:
ans =
1 3
ans =
1 2
EDIT — (12 Oct 2020 at 13:23)
Added example results.
.
  댓글 수: 2
Aleem Andrew
Aleem Andrew 2020년 10월 12일
Thank you for your help
Star Strider
Star Strider 2020년 10월 12일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by