필터 지우기
필터 지우기

Identify index of cell based on stringlength

조회 수: 2 (최근 30일)
chlor thanks
chlor thanks 2021년 5월 4일
댓글: chlor thanks 2021년 5월 4일
I have a cell array of such:
TStr =
1×1 cell array
{2×1 cell}
TStr{1}(1) =
1×1 cell array
{'Hello... It me, I was wondering if after all these years youd like to meet'}
TStr{1}(2) =
1×1 cell array
{'1800'}
I know that
strlength(TStr{1}(2))
= 4
How do I use this information to identify the index of the cell (in this case, index = 2) with stringlength of 4?

채택된 답변

Turlough Hughes
Turlough Hughes 2021년 5월 4일
Example data:
Tstr{1}{1,1} = 'Hello... It me, I was wondering if after all these years youd like to meet';
Tstr{1}{2,1} = '1800';
You can get the index by:
idx = cellfun(@numel,Tstr{1})==4;
Which gives:
Tstr{1}{idx}
ans = '1800'
  댓글 수: 4
Turlough Hughes
Turlough Hughes 2021년 5월 4일
The first is a logical index, the second is a linear index but both are indicating the position.
chlor thanks
chlor thanks 2021년 5월 4일
Oh I see! Thank you very much for your help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by