I want to normalize a vector in range -5 to +5. Is it possible?
이전 댓글 표시
답변 (2개)
Guillaume
2015년 6월 15일
Note that if all you want is generate random numbers between -5 and 5, it's actually one of the examples in the documentation of rand:
r = -5 + (5+5)*rand(10, 1)
Basically, it is
r = lowerbound + (upperbound - lowerbound) * rand
You can of course rescale your vector to whichever range you want:
vrescaled = (v - min(v)) * (newupper - newlower) / (max(v) - min(v)) + newlower
댓글 수: 2
Aditya Mhetras
2015년 6월 15일
Guillaume
2015년 6월 15일
Why couldn't it be? It's a basic linear transformation. As per the formula I've written:
vrescaled = (v - min(v)) * (newupper - newlower) / (max(v) - min(v)) + newlower
where newupper = 5 and newlower = -5, so:
vrescaled = (v - 1) * 10 / 9 - 5;
Andrei Bobrov
2015년 6월 15일
As wrote Guillaume:
variant 1:
out = A - 5; % if A >= 0 & A<=10
variant 2:
m = min(A(:));
out = (A(:)-m)/(max(A)-m)*10-5;
카테고리
도움말 센터 및 File Exchange에서 ROI-Based Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!