how to count repeated character in string ??

string loke this aaaaddccccfeeee how to count the repeating of character (a) a=3

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 29 日
編集済み: Azzi Abdelmalek 2014 年 3 月 29 日

3 投票

str='aaaaddccccfeeee'
[ii,jj,kk]=unique(str)
freq=histc(kk,1:numel(ii))
c=regexp(ii,'.','match')'
out=[c num2cell(freq)]

1 件のコメント

ahmed
ahmed 2014 年 3 月 29 日
alot of thanks thanks for your help

サインインしてコメントする。

その他の回答 (2 件)

Hassaan
Hassaan 2023 年 12 月 22 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2014 年 3 月 29 日

回答済み:

2023 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by