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
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
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.

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by