How to normalize a matrix such that each column sums equal 1
Show older comments
Hello,
I have a matrix A=[1 2 3; 1 3 6] and want to normalize the matrix such that each column sum equals 1.
The normalized matrix should be: P=[0.5 0.4 0.33; 0.5 0.6 0.67]
I tried these codes:
P=normc(A);
P=(A)/sum(A,1);
P=A/norm(A,1);
but they do not result in a matrix with column sums 1.
Can somebody give me some feedback?
Thank you in advance,
Clarisha
Accepted Answer
More Answers (1)
[row, col] = size(A);
for i=1:col
P(:,i)= A(:,i)/sum(A(:,i))
end
1 Comment
Clarisha Nijman
on 4 Oct 2018
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!