How could normalize a matrix between 0 and 1.
Show older comments
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.

Answers (2)
Stephan
on 2 May 2019
1 vote
result = normalize(x,2,'range')
11 Comments
Stephan
on 2 May 2019
Which release do you use?
Edu Gomez
on 2 May 2019
Edu Gomez
on 2 May 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
on 2 May 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
on 3 May 2019
Adam
on 3 May 2019
./ is point-wise division rather than matrix division
Stephen23
on 3 May 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
on 3 May 2019
0 votes
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!