How to count certain characters in a word?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to write a program, using loops and functions, that would count numbers of certain letters in a word.
For example if i input a word:'matlabprogram', and i want to count number of a,b,c,d letters in this word the program would say: a=3,b=3,c=0,d=0
Can you please help me?
P.S. sorry for my bad english
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 2 Apr. 2013
a = ('a':'d')'
b = 'matlabprogram'
out1 = [cellstr(a), num2cell(histc(b,a)')]
0 Kommentare
Weitere Antworten (1)
Azzi Abdelmalek
am 2 Apr. 2013
word='matlabprogram'
Lettre='abcd'
for k=1:numel(Lettre)
m=Lettre(k);
assignin('base',m,sum(ismember(word,m)))
end
1 Kommentar
Jan
am 2 Apr. 2013
Although the OP asked for the names "a", "b", ... this is not a smart idea and I'd definitely avoid suggesting assignin.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!