removing elements of a cell array
조회 수: 2 (최근 30일)
이전 댓글 표시
say we have a cell array
dictionary= 'abbreviately' 'abbreviation' 'abbreviator' 'abbreviatory' 'abbreviature' 'abby' 'abcoulomb' 'abdal'
I have written a code which returns x = 0 0 0 0 1 0 0
word='saddest'
newguess='e'
x=newguess==word
How do I delete the words from dictionary that are not equivalent for my x value and newguess letter 'e'. So x has a true value on the 5th position (after the 4 false values), which would mean I would like to delete all the words from dictionary if their 5th position letter does not equal 'e'. Thank you
댓글 수: 0
채택된 답변
Walter Roberson
2015년 11월 8일
newdictionary = C( cellfun(@(C) length(C) >= 5 & C(5)==newguess, dictionary, 'Uniform', 0) );
댓글 수: 5
Walter Roberson
2015년 11월 8일
The code I gave assumed a cell array of strings, so it should be fine with that definition of your dictionary.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!