how to count repeated character in string ??

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Mzo. de 2014
Editada: Azzi Abdelmalek el 29 de Mzo. de 2014
str='aaaaddccccfeeee'
[ii,jj,kk]=unique(str)
freq=histc(kk,1:numel(ii))
c=regexp(ii,'.','match')'
out=[c num2cell(freq)]

Más respuestas (2)

Hassaan
Hassaan el 22 de Dic. de 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

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 29 de Mzo. de 2014

Respondida:

el 22 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by