How could normalize a matrix between 0 and 1.
Afficher commentaires plus anciens
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.

Réponses (2)
Stephan
le 2 Mai 2019
1 vote
result = normalize(x,2,'range')
11 commentaires
Stephan
le 2 Mai 2019
Which release do you use?
Edu Gomez
le 2 Mai 2019
Edu Gomez
le 2 Mai 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.
Adam
le 2 Mai 2019
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.
Edu Gomez
le 3 Mai 2019
Adam
le 3 Mai 2019
./ is point-wise division rather than matrix division
Stephen23
le 3 Mai 2019
"And one more question, whats means " ./ " ????"
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
le 3 Mai 2019
0 votes
Catégories
En savoir plus sur Sparse Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
