Vector mapping means changing the range of a vector from range-1 to range-2. For instance, if a vector is in range [2,12] and we want to scale the vector and map it to range [0,2]. I give you some useful hints here:

**Case-1: mapping from [0,1] to [a,b]: **

if the vector is in range v1 ∈ [0,1] and we want to convert it to range v2 ∈ [a,b], the following formulation works:

**v2 = a + (b-a) * v1**

example:

v1 = rand(100,1); %vector in range [0,1]
v2 = -2 + (3-(-2)).*v1; %vector in range [-2,3]

**Case-2: mapping from [a,b] to [0,1]:**

if the vector is in range v1 ∈ [a,b] and we want to convert it to range v2 ∈ [0,1], the following formulation works:

**v2 = (v1 - a) / (b-a)**

example:

v1 = linspace(-5,2,100); %vector in range [-5,2]
v2 = (v1-(-5)) ./ (2-(-5)); %vector in range [0,1]

**Case-3: mapping from [-1,1] to [a,b]:**

if the vector is in range v1 ∈ [-1,1] and we want to convert it to range v2 ∈ [a,b], the following formulation works:

**v2 = ((b+a) + (b-a) * v1) / (1-(-1))**

example:

v1 = linspace(-1,1,100); % vector in range [-1,1]
v2 = (4-2)/2 + ((4-(-2))/(1-(-1))).*v1; % vector in range [-2,4]

**Case-4: mapping from [a,b] to [-1,1]:**

if the vector is in range v1 ∈ [a,b] and we want to convert it to range v2 ∈ [-1,1], the following formulation works:

**v2 = [(1-(-1))*v1 - (a+b)] / (b-a)**

example:

v1 = linspace(-2,4,100); %vector in range [-2,4]
v2 = ((1-(-1))*v1 - (-2+4)) / (4-(-2)); %vector in range [-1,1]

**Case-5: mapping from [a,b] to [c,d]:**

In the most general case, if the vector is in range v1 ∈ [a,b] and we want to convert it to range v2 ∈ [c,d], the conversion can be seen as a mapping from the first vector to [-1,1] and then mapping from [-1,1] to [c,d]. the following formulation works:

**v1 ∈ [a,b] → [-1,1] → v2 ∈ [c,d]**

**v2 = [ (c+d) + (d-c)* [(2*v1 - (a+b)) / (b-a)] ] / 2**

example:

v1 = linspace(-2,9,100); %vector in range [-2,9]
v2 = 0.5* ((-5+3) + (3-(-5))*((2*v1 - (-2+9))/(9-(-2))) ); %vector in range [-5,3]

Matlab Function for linear mapping from [a,b] to [c,d]:

function vout = linmap(vin,rout)
% function for linear mapping between two ranges
% inputs:
% vin: the input vector you want to map, range [min(vin),max(vin)]
% rout: the range of the resulting vector
% output:
% vout: the resulting vector in range rout
% usage:
% >> v1 = linspace(-2,9,100);
% >> v2 = linmap(v1,[-5,5]);
%
a = min(vin);
b = max(vin);
c = rout(1);
d = rout(2);
vout = ((c+d) + (d-c)*((2*vin - (a+b))/(b-a)))/2;
end

The equivalent function in python is presented in this post.