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

1 次查看(过去 30 天)
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