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

3 visualizaciones (últimos 30 días)
sara adam
sara adam el 21 de Nov. de 2018
Respondida: piyush makwana el 29 de Nov. de 2020
my-string= 'ABCCBA'
my_character=['A','B','C'];
  5 comentarios
Guillaume
Guillaume el 21 de Nov. de 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 el 21 de Nov. de 2018
my string = specifict character such as ****@@@@---(())
I wanna count the number of that
output is for example *=2
@=2

Iniciar sesión para comentar.

Respuestas (2)

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

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by