Filter löschen
Filter löschen

finding highest values in string

10 Ansichten (letzte 30 Tage)
James Connor
James Connor am 12 Nov. 2015
Beantwortet: Mohammad Abouali am 13 Nov. 2015
say I have a string x='asdqweqweasdddasdaaaaaaaaasdeeeeeer' and another string y='aed' how do I find the letter that occurs in x the most as long as its not in y so for example the most common letter in x is 'a' we ignore 'a' and find the second most common letter in x that does not appear in y which is 'e' we ignore 'e' because it appears in x we do this until we find the highest occurring letter in x that does not appear in y

Akzeptierte Antwort

Mohammad Abouali
Mohammad Abouali am 13 Nov. 2015
x='asdqweqweasdddasdaaaaaaaaasdeeeeeer';
y='aed';
uniqueCharsNotInY=unique(x(~ismember(x,y)));
charCount=arrayfun(@(c) sum(x==c),uniqueCharsNotInY');
mostRepeatedCharNotInY=uniqueCharsNotInY(charCount==max(charCount))
mostRepeatedCharNotInY =
s

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by