I want to normalize a vector in range -5 to +5. Is it possible?

답변 (2개)

Guillaume
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

can a vector A=[1 2 3 4 5 6 7 8 9 10] be normalozed in interval -5 to +5?
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
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;

태그

질문:

2015년 6월 15일

댓글:

2015년 6월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by