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.

답변 (2개)
Stephan
2019년 5월 2일
1 개 추천
result = normalize(x,2,'range')
댓글 수: 11
Stephan
2019년 5월 2일
Which release do you use?
Edu Gomez
2019년 5월 2일
Edu Gomez
2019년 5월 2일
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
2019년 5월 2일
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
2019년 5월 3일
Adam
2019년 5월 3일
./ is point-wise division rather than matrix division
Stephen23
2019년 5월 3일
"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);
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
