필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Anonymous Matrix
Anonymous Matrix 2017년 2월 15일
댓글: Anonymous Matrix 2017년 2월 15일
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