i want to generate a profile matrix of given numbers of letters as matrix form
6 ビュー (過去 30 日間)
古いコメントを表示
i want a profile matrix like
a b c a
a c c b
c b a b
then it will create a profile matrix of
a 2 0 1 1
b 0 2 0 2
c 1 1 2 0
i.e it count column wise letter present. i have given an small example. but i have to proceed for numerous number of letters.
1 件のコメント
Jan
2016 年 3 月 30 日
If your question starts with "I have a profile matrix", an answer would be easier. But that you only want such a matrix, requires a massive guessing of what you problem is.
What does "numerous letters" mean? There are only 26 letters, or 52 considering uppercase. How do you want to represent the 53rd element? What about avoiding letters and using numbers directly?
回答 (1 件)
Image Analyst
2016 年 3 月 30 日
This will work.
c = ['a' 'b' 'c' 'a'
'a' 'c' 'c' 'b'
'c' 'b' 'a' 'b']
% Convert to numbers
cNum = c - 'a' + 1;
[rows, columns] = size(cNum);
counts = zeros(26, columns);
for col = 1 : columns
thisColumn = cNum(:, col);
% Get histograms
theseCounts = histcounts(thisColumn, [1:27])
counts(:,col) = theseCounts;
end
% Display result in command window.
counts
There are lots of ways to adapt it, such as making the counts array only as tall as the highest letter that is present, or having it handle capital letters also, etc. Feel free to adapt it however you want.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!