i want to generate a profile matrix of given numbers of letters as matrix form

6 Ansichten (letzte 30 Tage)
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 Kommentar
Jan
Jan am 30 Mär. 2016
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 30 Mär. 2016
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.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by