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

Answers (2)

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 Comments

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;

Sign in to comment.

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;

Asked:

on 15 Jun 2015

Commented:

on 15 Jun 2015

Community Treasure Hunt

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

Start Hunting!