Effacer les filtres
Effacer les filtres

How do I eliminate strings with length < 3 from cellarray

2 vues (au cours des 30 derniers jours)
Eduardo
Eduardo le 6 Déc 2013
Commenté : Eduardo le 6 Déc 2013
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.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 6 Déc 2013
days = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
abbrev = days(cellfun(@numel,days)>=3)

Plus de réponses (1)

sixwwwwww
sixwwwwww le 6 Déc 2013
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 commentaire
Eduardo
Eduardo le 6 Déc 2013
I've implemented one similar to that. But its too slow for big cell arrays.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by