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

2 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2017-2-15
>> a = {'cat';'dog';'hamster';'shark';'duck';'bat'};
>> a(cellfun('length',a)>3)
ans =
'hamster'
'shark'
'duck'
  3 个评论
Stephen23
Stephen23 2017-2-15
编辑:Stephen23 2017-2-15
@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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by