Hwo to normalize a Matrix ?

조회 수: 6 (최근 30일)
RT Student
RT Student 2021년 8월 15일
편집: Image Analyst 2022년 1월 25일
what is the code to normalize a random complex matrix H according to the following formula:

채택된 답변

Fabio Freschi
Fabio Freschi 2021년 8월 16일
편집: Fabio Freschi 2021년 8월 16일
Following the formula of the OT the normalization has to be done according to the max and min of each row. Note that the matrix in the comment is actually a real matrix. The solution should be:
% random 4x3 matrix
H = abs(sqrt(1/2)*(randn(16,4)+1j*randn(16,4)));
% min/max along the rows
hMin = min(H,[],2);
hMax = max(H,[],2);
% normalization (binary singleton expansion is implicit since Matlab 2016b)
H = (H-hMin)./(hMax-hMin);
In this way, each element in a row is in the range [0 1]
  댓글 수: 2
RT Student
RT Student 2021년 8월 16일
Thank you!
영우 오
영우 오 2022년 1월 25일
Thank you!!

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

추가 답변 (2개)

Image Analyst
Image Analyst 2021년 8월 15일
편집: Image Analyst 2022년 1월 25일
Well I don't know about complex numbers, but for a normal, real valued matrix, you can use the rescale() function, introduced in r2017b:
h = rescale(h, 0, 1);
  댓글 수: 3
Fabio Freschi
Fabio Freschi 2021년 8월 16일
@Image Analyst suggested
H=rescale(H,0,1); % 0 as second input, 1 as third input
Howewer rescale apply rescaling with respecto to the matrix min and max, while the formula refers to the min and max along each row. See also my answer
Image Analyst
Image Analyst 2021년 8월 16일
@RT Student the code you gave worked just fine. No error at all. Even when I correct rescale(H, 1, 0) to what I had, rescale(H, 0, 1) it still works.
However Fabio is right - the formula normalizes on a row-by-row basis, not globally like my solution did.
His answer is good and more closely follows your formula. Thanks for accepting it. If you wanted to use the built-in rescale(), you'd have to do it on a row-by-row basis:
% Create data. Note, because of abs() it is all real valued.
H = abs(sqrt(1/2)*(randn(16,4)+1j*randn(16,4)))
% Rescales to global min and max.
%H = rescale(H, 0, 1)
% Rescales min and max to 0-1 on a row-by-row basis.
for row = 1 : size(H, 1)
H(row, :) = rescale(H(row, :), 0, 1);
end

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


Steven Lord
Steven Lord 2021년 8월 16일
Take a look at the normalize function.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by