How could normalize a matrix between 0 and 1.
Ältere Kommentare anzeigen
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.

Antworten (2)
Stephan
am 2 Mai 2019
1 Stimme
result = normalize(x,2,'range')
11 Kommentare
Stephan
am 2 Mai 2019
Which release do you use?
Edu Gomez
am 2 Mai 2019
Edu Gomez
am 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
am 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
am 3 Mai 2019
Adam
am 3 Mai 2019
./ is point-wise division rather than matrix division
Stephen23
am 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
am 3 Mai 2019
0 Stimmen
Kategorien
Mehr zu Sparse Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
