removing elements of a cell array

1 回表示 (過去 30 日間)
James Connor
James Connor 2015 年 11 月 8 日
コメント済み: James Connor 2015 年 11 月 8 日
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

採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 8 日
newdictionary = C( cellfun(@(C) length(C) >= 5 & C(5)==newguess, dictionary, 'Uniform', 0) );
  5 件のコメント
Walter Roberson
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.
James Connor
James Connor 2015 年 11 月 8 日
Oh, I don't know if it's me doing something wrong but I keep getting this.
Index exceeds matrix dimensions.
Error in @(C)length(C)==length(x)&all(C(x)==newguess)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by