필터 지우기
필터 지우기

Normalize matrix elements resulting in sum of elements of one.

조회 수: 23 (최근 30일)
Ihiertje
Ihiertje 2017년 11월 28일
편집: Jan 2017년 11월 28일
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
Ihiertje
Ihiertje 2017년 11월 28일
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!
Jan
Jan 2017년 11월 28일
편집: Jan 2017년 11월 28일
Then see my answer, which divides all elements by the sum over all elements. In consequence the sum equals 1 (beside rounding errors).

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2017년 11월 28일
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.

KSSV
KSSV 2017년 11월 28일
A = magic(5) ;
B = A ;
for i = 1:5
B(:,i) = A(:,i)./norm(A(:,i),1) ;
end
sum(B)
  댓글 수: 2
Ihiertje
Ihiertje 2017년 11월 28일
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.
KSSV
KSSV 2017년 11월 28일
It normalizes every column.....so sum of columns will be 1.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by