how to count repeated character in string ??
Show older comments
string loke this aaaaddccccfeeee how to count the repeating of character (a) a=3
Accepted Answer
More Answers (2)
Jan
on 29 Mar 2014
str = 'aaaaddccccfeeee';
[b, n] = RunLength(str)
Hassaan
on 22 Dec 2023
To count the occurrences of a specific character in a string in MATLAB, you can use the count function.
str = 'aaaaaddddccceeeeee'; % The string to search
characterToCount = 'a'; % The character you want to count
% Count the occurrences
occurrences = count(str, characterToCount);
% Display the result
fprintf('The character "%s" appears %d times in the string.\n', characterToCount, occurrences);
Output
The character "a" appears 5 times in the string
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!