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

1 view (last 30 days)
A vector like v=rand(1,10)*5+1

Answers (2)

Guillaume
Guillaume on 15 Jun 2015
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
Aditya Mhetras
Aditya Mhetras on 15 Jun 2015
can a vector A=[1 2 3 4 5 6 7 8 9 10] be normalozed in interval -5 to +5?
Guillaume
Guillaume on 15 Jun 2015
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.


Andrei Bobrov
Andrei Bobrov on 15 Jun 2015
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;

Categories

Find more on Portfolio Optimization and Asset Allocation 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!