Normalize matrix elements resulting in sum of elements of one.

Hi,
For part of my matlab code I have to normalize a space-variant matrix K:
K[u][v](x,y)
so that the sum (u and v) of all locations in this matrix after normalization is 1:
∑∑K[u][v](x,y) = 1
However, I'm not sure where to begin with this. Could someone help me with the steps I should take?
Thanks!

8 Comments

Hi, can you post an example of what you're looking to do? Is it orthogonalization that you're trying to attempt?
I'm not sure what kind of example you are asking for. I found this part in a thesis and would like to apply it. So unfortunately I don't have more information.
LEARN to think in MATLAB terms, at least to express yourself that way when you are talking MATLAB.
This means little in terms of a question about MATLAB:
K[u][v](x,y)
Does it mean that you have a 4 dimensional matrix K? Or does it mean that at any location in space, thus the (x,y) plane, the matrix elements must sum to 1?
If the latter is the case, then are the elements of a square matrix K, thus K(u,v), each functions of x and y? So is K a symbolic array? Or is K itself essentially a function of the location in the coordinate plane thus you have a function that takes in (x,y) coordinates, and returns a matrix K?
Unless you explain what you mean, then no answer is really possible.
What exactly is "a space-variant matrix K:K[u][v](x,y)"? Remember, that the members of this forum understand Matlab syntax, but the vast majority of them will not work in your field of science. But as long as Matlab understand Matlab only also, it is worth to reformulate the question in a a way, which can be understood by Matlab. Please edit your question and append more details.
Sorry, here some more information:
K is a two dimensional, 512x512 matrix of which the values varies with the location in the corresponding image. Therefore, (x,y) is any pixel location in the image and (u,v) are the pixel locations in the source (512x512 and 2D). Therefore, the values in K changes with (u,v).
Ultimately each pixel location (u,v) results in a specific value in the (x,y) positions. And from the earlier mentioned equation the normalization needs to be determined. Hopefully this explains more about my problem.
@Ihiertje: Almost clear now. So is your input is e.g.
X = rand(512, 512)
or
X = randi([1, 512], 512, 512)
? Now explain, what should be normalized now: The sum over the columns, over the rows or over all elements?
The input is X=rand(x,y), where x and y are values between 1 and 512. And the normalization should be over all elements. Thanks for your time and effort by the way!
Then see my answer, which divides all elements by the sum over all elements. In consequence the sum equals 1 (beside rounding errors).

Sign in to comment.

Answers (2)

Perhaps you want:
A = rand(5, 5); % Test data
B = A / sum(A(:))
If you want something else, please explain which sum should be 1.
A = magic(5) ;
B = A ;
for i = 1:5
B(:,i) = A(:,i)./norm(A(:,i),1) ;
end
sum(B)

2 Comments

I adjusted your code to my problem and tried it, but I don't think it is right at the moment as it does not result in a sum of 1.
It normalizes every column.....so sum of columns will be 1.

Sign in to comment.

Asked:

on 28 Nov 2017

Edited:

Jan
on 28 Nov 2017

Community Treasure Hunt

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

Start Hunting!