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

1 view (last 30 days)
my-string= 'ABCCBA'
my_character=['A','B','C'];
  5 Comments
Guillaume
Guillaume on 21 Nov 2018
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 on 21 Nov 2018
my string = specifict character such as ****@@@@---(())
I wanna count the number of that
output is for example *=2
@=2

Sign in to comment.

Answers (2)

Guillaume
Guillaume on 21 Nov 2018
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 on 29 Nov 2020
my srting ='pilani';lower(mystring)
what is out put result

Tags

Community Treasure Hunt

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

Start Hunting!