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.

Respuestas (2)

Stephan
Stephan el 2 de Mayo de 2019

1 voto

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

11 comentarios

Edu Gomez
Edu Gomez el 2 de Mayo de 2019
Editada: Edu Gomez el 2 de Mayo de 2019
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 el 2 de Mayo de 2019
Which release do you use?
Edu Gomez
Edu Gomez el 2 de Mayo de 2019
Matlab R2015a
Stephan
Stephan el 2 de Mayo de 2019
Editada: Stephan el 2 de Mayo de 2019
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 el 2 de Mayo de 2019
Editada: Stephan el 2 de Mayo de 2019
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 el 3 de Mayo de 2019
./ is point-wise division rather than matrix division
Stephen23
Stephen23 el 3 de Mayo de 2019
Jan
Jan el 3 de Mayo de 2019
Editada: Jan el 3 de Mayo de 2019
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);

Iniciar sesión para comentar.

Edu Gomez
Edu Gomez el 3 de Mayo de 2019

0 votos

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 :))

Categorías

Más información sobre Sparse Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Mayo de 2019

Editada:

Jan
el 3 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by