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 Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by