On 11/21/2012 5:58 PM, zuzia wrote:
...[top posting repaired--please don't do that--hard follow conversation
makes]...
Post by zuzia Post by dpbPost by zuzia I'm working on a specific matrix and I need to normalize the sum of the
elements in all the rows and all the columns to be equal to 1. I have
managed to create the codes to do both separately but does anyone know
how to obtain both simultaneously?
thank you!!!
Taking "all the rows and all the columns" literally,
x=x/sum(x(:));
If you mean each row and column simultaneously to sum to 1, otomh I
don't think there's a guarantee that has a solution; at least w/
linear weights.
It would be S_j(w(i,j).*x(i,j)) + S_i(w(i,j).*x(i,j)) = 2
and try to solve for w
Yes, I meant EACH of them equal to 1, not all of them simultaneously.
B = A;
columnSums = sum(B);
for i = 1:numel(columnSums)
B(:,i) = B(:,i)./columnSums(i);
end
(for summing the columns)
and B = A;
rowSums = sum(transpose (A));
for j = 1:numel(rowSums)
B(j,:) = B(j,:)./rowSums(j);
end
(for summing the rows).
Post by dpbDo you think it's possible just to impose a condition applying them both
together? Or otherwise maybe you could please explain your command?
I don't see how. You've got nXm coefficients to determine from only n+m
equations.
As for the above, you can write it as
B=A./repmat(sum(A),size(A,1),1); % columns
B=A./repmat(sum(A,2),1,size(A,2)); % columns
I'm still not clear on what you really mean w/ "not all simultaneously"
and then "applying both together". It seems to be s dichotomy.
But if you mean just one row/column pair at a time, consider a 2x2
example. You'd have
x(1,1)*w(1,1)+x(2,1)*w(2,1)=1 % 1st column
x(1,1)*w(1,1)+x(1,2)*w(1,2)=1 % 1st row
That's determining three unknown weights w/ only two equations and as
the array gets larger you add more weights but no more constraints.
--