How do I eliminate strings with length < 3 from cellarray
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Azzi Abdelmalek
2013-12-6
days = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
abbrev = days(cellfun(@numel,days)>=3)
更多回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!