i want to generate a profile matrix of given numbers of letters as matrix form
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Jan
el 30 de Mzo. de 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?
Respuestas (1)
Image Analyst
el 30 de Mzo. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Operators and Elementary Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!