Checking to see if a character is in a string array, then deleting entries where this character isn't in a string

3 ビュー (過去 30 日間)
I have a string array that is just a list of words (dictionary), a random word (word) is selected and I want to loop though the alphabet, then if, say 'a' isn't in my random word it will delete all entries in my string array that contain 'a' etc. (Warning you now, I'm new to matlab).
for i=alphabet;
if i==word;
strfind(dictionary,i);
sel(i)=true;
end
end
rows=find(sel);
newdictionary=dictionary(sel);
this isn't working, so any help with fixing it would be really appreciated

採用された回答

Thorsten
Thorsten 2015 年 11 月 10 日
編集済み: Thorsten 2015 年 11 月 13 日
To delete all entries with an 'a' from your dictionary
dictionary = {'a' 'b' 'ba' 'c' 'hallo'};
idx = ~cellfun(@isempty, strfind(dictionary, 'a'));
dictionary(idx) = [];
To select a random word from your dictionary
word = dictionary(randi(numel(dictionary)));
Now you can loop over the characters in word to remove all entries in dictionary that have this character.
  2 件のコメント
regina
regina 2015 年 11 月 13 日
Thank you very much, this helped a lot!
regina
regina 2015 年 11 月 13 日
Thank you very much, this helped a lot!

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by