Effacer les filtres
Effacer les filtres

how to count repeated character in string ??

30 vues (au cours des 30 derniers jours)
ahmed
ahmed le 29 Mar 2014
Réponse apportée : Hassaan le 22 Déc 2023
string loke this aaaaddccccfeeee how to count the repeating of character (a) a=3

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 29 Mar 2014
Modifié(e) : Azzi Abdelmalek le 29 Mar 2014
str='aaaaddccccfeeee'
[ii,jj,kk]=unique(str)
freq=histc(kk,1:numel(ii))
c=regexp(ii,'.','match')'
out=[c num2cell(freq)]
  1 commentaire
ahmed
ahmed le 29 Mar 2014
alot of thanks thanks for your help

Connectez-vous pour commenter.

Plus de réponses (2)

Jan
Jan le 29 Mar 2014

Hassaan
Hassaan le 22 Déc 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

Catégories

En savoir plus sur Characters and Strings 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