How could normalize a matrix between 0 and 1.

I have a matrix 14x15536 how it shows in the picture, and i would like to normalize each row between 0 and 1.
How could I do it??
Thanks in advance.

답변 (2개)

Stephan
Stephan 2019년 5월 2일

1 개 추천

result = normalize(x,2,'range')

댓글 수: 11

Edu Gomez
Edu Gomez 2019년 5월 2일
편집: Edu Gomez 2019년 5월 2일
Thanks for you quick answer.
Always I try to use "normalize" I recive this error: Undefined function 'normalize' for input arguments of type 'double'.
Function "normalize" is for normalizating between -1 and 1, is it true??
How could I solve it??
Thanks again in advance.
Stephan
Stephan 2019년 5월 2일
Which release do you use?
Edu Gomez
Edu Gomez 2019년 5월 2일
Matlab R2015a
Stephan
Stephan 2019년 5월 2일
편집: Stephan 2019년 5월 2일
Then use this function:
function result = myNormalizer(x)
result = zeros(size(x));
for k = 1:size(x,1)
result(k,:) = (x(k,:) - min(x(k,:))) ./ max(x(k,:) - min(x(k,:)));
end
end
Thank you so much Stephan, now the algorithm goes right. Only I have seen one thing more to implement, and the row 4 is always 2.5, so it is impossible to the algorithm identify min and max, and it shows "NaN". I don´t know if I have to give for this value 1 or 0.
I have thought this, what do you think about??
Thanks for you help and your time in advance. Im very pleased tu you, and sorry for my poor english, I need to improve it.
function result = Normalize(x)
% result = zeros(size(x));
[varFil,~]=size(x);
for i=1:varFil
if min(x(i,:))==max(x(i,:))
x(i,:)=1; % I don´t know if it is correct.
else
result(i,:) = (x(i,:) - min(x(i,:))) ./ max(x(i,:) - min(x(i,:)));
end
end
end
But I see this:
Captura.JPG
Stephan
Stephan 2019년 5월 2일
편집: Stephan 2019년 5월 2일
I dont think that you can say it is correct to set this equal to one. It would also not be correct to set it to zero. You do a division of zero by zero - this leads to a NaN value. However, the inbuilt normalize function treats this with setting the values equal to zero.
You can do it in vectorised form without the need of a for loop as:
rowMin = min( x, [], 2 );
result = ( x - rowMin ) ./ ( max( x, [], 2 ) - rowMin );
You will still get the same divide by 0 problem though if you have a constant row because you could 'normalise' it to any value between 0 and 1 equally so you have to just majke a choice depending on your usage.
Thank you for your answer, i would like to try also this opction in order to learn more about Matlab.
So, I see this error with that:
function result = Normalizar(x)
rowMin = min( x, [], 2 );
result = ( x - rowMin ) ./ ( max( x, [], 2 ) - rowMin );
end
I have seen this error several times, and I dont´t know how interpretate this (-) with dimensions, I don´t know how Matlab works for doing: ( x - rowMin ).
And one more question, whats means " ./ " ????
Thanks in advance
Adam
Adam 2019년 5월 3일
./ is point-wise division rather than matrix division
Jan
Jan 2019년 5월 3일
편집: Jan 2019년 5월 3일
Edu Gomez uses R2015a, so no auto-expanding, which was introduced in R2016b. Then bsxfun is required:
rowMin = min(x, [], 2);
result = bsxfun(@minus, x, rowMin) ./ bsxfun(@minus, max(x, [], 2), rowMin);

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

Edu Gomez
Edu Gomez 2019년 5월 3일

0 개 추천

I want say thanks to both for you time and your help, Its very rewarding to have your help for this. Im doing a master thesis and I need a little help with Matlab sometimes.
Thank you very much :))

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

질문:

2019년 5월 2일

편집:

Jan
2019년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by