필터 지우기
필터 지우기

How do I eliminate strings with length < 3 from cellarray

조회 수: 1 (최근 30일)
Eduardo
Eduardo 2013년 12월 6일
댓글: Eduardo 2013년 12월 6일
I'm trying to remove all string with length < 3 from a cell array. But the output is not what I expect.
For example:
days = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'}; abbrev = cellfun(@(x) x(length(x) > 3), days, 'UniformOutput', false)
It returns:
abbrev =
'M' 'T' 'W' 'T' 'F'
But I need it to return the whole word that is bigger than 3.
Anyone knows how to do it?
Thanks.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 6일
days = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
abbrev = days(cellfun(@numel,days)>=3)

추가 답변 (1개)

sixwwwwww
sixwwwwww 2013년 12월 6일
try this:
days = {'Monday', 'M', 'T', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
count = 1;
for i = 1:length(days)
if length(days{i}) > 3
day(count) = days(i);
count = count + 1;
end
end
  댓글 수: 1
Eduardo
Eduardo 2013년 12월 6일
I've implemented one similar to that. But its too slow for big cell arrays.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by