Hi guys how can I put my-string in input of matlab?

조회 수: 1 (최근 30일)
sara adam
sara adam 2018년 11월 21일
답변: piyush makwana 2020년 11월 29일
my-string= 'ABCCBA'
my_character=['A','B','C'];
  댓글 수: 5
Guillaume
Guillaume 2018년 11월 21일
What is this string and what is the input? I still have no idea what you want.
Note that the code you've posted can be simplified to:
my_string = '@**.. @';
my_characters = '@.*&'; %again there is no difference with ['@', '.', '*', '&']
[sortedchars, origorder] = sort(my_characters); %required for histcounts
my_characters_count = histcounts(double(my_string), [double(sortedchars), Inf]);
my_characters_count = my_characters_count(origorder);
sara adam
sara adam 2018년 11월 21일
my string = specifict character such as ****@@@@---(())
I wanna count the number of that
output is for example *=2
@=2

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2018년 11월 21일
As per my comment, your double for loop to compute the histogram of the characters can be replaced by:
my_string = '@**.. @';
my_characters = '@.*&'; %again there is no difference with ['@', '.', '*', '&']
[sortedchars, origorder] = sort(my_characters); %required for histcounts
my_characters_count = histcounts(double(my_string), [double(sortedchars), Inf]);
my_characters_count = my_characters_count(origorder);
You can display the result in many ways. For example:
disp(strjoin(compose('%c = %d', my_characters', my_characters_count'), '\n'))
Personally, I'd just put the results in a table:
t = table(my_characters', my_characters_count', 'VariableNames', {'character', 'count'})

piyush makwana
piyush makwana 2020년 11월 29일
my srting ='pilani';lower(mystring)
what is out put result

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by