How to normalize values in a matrix to be between 0 and 1?
85 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sahar abdalah
el 8 de Abr. de 2015
Comentada: Tubi
el 22 de Mzo. de 2018
I have a matrix Ypred that contain negative values and I want to normalize this matrix between 0 and 1
Ypred=[-0.9630 -1.0107 -1.0774
-1.2075 -1.4164 -1.2135
-1.0237 -1.0082 -1.0714
-1.0191 -1.3686 -1.2105];
I'm new in matlab, please help me, there is a matlab function or toolbox that can do this? thanks
2 comentarios
James Tursa
el 8 de Abr. de 2015
Editada: James Tursa
el 8 de Abr. de 2015
What do you mean by "normalize"? Divide by the max value in the matrix and make all values positive? Do this by columns or rows? Divide by norm of columns or rows? Or what?
Respuesta aceptada
Jos (10584)
el 8 de Abr. de 2015
Editada: Jos (10584)
el 8 de Abr. de 2015
This can be simply done in a two step process
- subtract the minimum
- divide by the new maximum
normA = A - min(A(:))
normA = normA ./ max(normA(:)) % *
note that A(:) makes A into a long list of values. Otherwise min(A) would not return a single value ... Try fro yourself!
- Edited after comment ...
2 comentarios
Jos (10584)
el 8 de Abr. de 2015
Sorry! The second line of code is wrong ;-) It should read
normA = normA ./ max(normA(:))
Más respuestas (3)
James Tursa
el 8 de Abr. de 2015
NormRows = sqrt(sum(Ypred.*Ypred,2));
Ynorm = bsxfun(@rdivide,abs(Ypred),NormRows);
3 comentarios
John D'Errico
el 10 de Mzo. de 2018
Editada: John D'Errico
el 10 de Mzo. de 2018
Why would you need a citation? If you truly want a citation, just cite MATLAB itself, or perhaps the doc page for bsxfun, but it seems a bit silly to need a citation for a simple code fragment.
Tubi
el 22 de Mzo. de 2018
Many Thanks John, I believe you are right in your suggestion since they are mostly common MATLAB commands and functions.
Sahar abdalah
el 9 de Abr. de 2015
2 comentarios
James Tursa
el 9 de Abr. de 2015
Use whichever is appropriate for your problem. Jos and I are both trying to interpret what you want, but without any background about the problem you are solving it is a bit of a guessing game at our end.
c4ndc
el 12 de Ag. de 2017
Hello, What is the name of this norm in the accepted answer? (Euclidean, Frobenius etc.)
1 comentario
Jan
el 12 de Ag. de 2017
Please post comments to answers in the section for the comments. You message is not an answer.
The accepted answer does not contain a norm at all, but a "normalization". A matrix norm would reply a scalar, the normalization replies a matrix with the same size, but with shifted and scaled values.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!