taking second mode from strings

1 vue (au cours des 30 derniers jours)
Max
Max le 11 Nov 2015
Commenté : Thorsten le 11 Nov 2015
I want to write something that takes the most common letter from a cell array of it does not appear in another string
newguess=char(mode(+[dict{:}])); %gives the most common letter out of a cell array of words
Say pastguesses='eas' and newguess='e' I want to return the second most common letter until newguess doesn't appear in pastguesses.
I tried something like
if newguess==pastguesses
%take next most common newguess until newguess doesn't appear in pastguesses
end

Réponses (1)

Thorsten
Thorsten le 11 Nov 2015
You can compress your dictionary to a single string of letters and then remove the most common letter from the string. Then find the second most common letter in this string. Note that I used double instead of + to convert from char to double, because it is easier to understand:
dict = {'a' 'b' 'ba' 'c' 'hallo'};
letters = [dict{:}];
mostcommon = char(mode(double(letters)))
newletters = strrep(letters, mostcommon, '')
secondmostcommon = char(mode(double(newletters)))
  2 commentaires
Max
Max le 11 Nov 2015
newguess=char(mode(+[dict{:}])); %gives the most common letter out of a cell array of words
I mean is it possible to take the highest appearing letter that is not in pastguesses from example if pastguesses='eai' and newguess='e' I ignore newguess and take the second most common letter so newguess='a' but newguess='a' appears in pastguesses so we take the next most common letter so newguess='i' but it appears in pastguesses so we take the next most common letter say newguess='o' 'o' doesnt appear in pastguesses so we stop at newguess='o'
The newguess is generated from a list of words and pastguesses keeps getting updated in my code. so for example say
dict= {'aa';'aal';'aalii';'aam';'aani';'aardvark';'aardwolf';'aaron';'aaronic';'aaronical';'aaronite';'aaronitic';'aaru';'ab';'aba';'ababdeh';'ababua';'abac';'abaca';'abacate'}
newguess= %is the highest occuring letter in dict that does not appear in pastguesses.
Thanks for the help.
Thorsten
Thorsten le 11 Nov 2015
You remove the letters in passguesses from the letters in your dictionary, and then determine the mode of the remaining letters:
dict= {'aa';'aal';'aalii';'aam';'aani';'aardvark';'aardwolf';'aaron';'aaronic';'aaronical';'aaronite';'aaronitic';'aaru';'ab';'aba';'ababdeh';'ababua';'abac';'abaca';'abacate'}
letters = [dict{:}];
pastguesses='eas'
for i=1:length(pastguesses)
letters = strrep(letters, pastguesses(i), '');
end
mostcommonnotinpastguesses = char(mode(double(letters)))

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by