필터 지우기
필터 지우기

how to count repeated character in string ??

조회 수: 30 (최근 30일)
ahmed
ahmed 2014년 3월 29일
답변: Hassaan 2023년 12월 22일
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일
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개)

Jan
Jan 2014년 3월 29일

Hassaan
Hassaan 2023년 12월 22일
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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by