Effacer les filtres
Effacer les filtres

How do I use use logical relations on a character array?

2 vues (au cours des 30 derniers jours)
Anonymous Matrix
Anonymous Matrix le 15 Fév 2017
Commenté : Anonymous Matrix le 15 Fév 2017
Say like I have an array animals=[cat;dog;hamster;shark;duck;bat]. How do I get an array that only contains animals that is spelled with 4 or more letters?

Réponse acceptée

Stephen23
Stephen23 le 15 Fév 2017
>> a = {'cat';'dog';'hamster';'shark';'duck';'bat'};
>> a(cellfun('length',a)>3)
ans =
'hamster'
'shark'
'duck'
  3 commentaires
Stephen23
Stephen23 le 15 Fév 2017
Modifié(e) : Stephen23 le 15 Fév 2017
@Anonymous Matrix: no you do not have to type out each name again. I used the variable name a as an example. Use whatever variable you have been given, e.g.:
name_of_your_variable(cellfun('length',name_of_your_variable)>3)
Anonymous Matrix
Anonymous Matrix le 15 Fév 2017
thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional 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