Clear Filters
Clear Filters

how to scale the array type double of range [-1,1] to [0,1] and [0,360] to[0,1]

12 views (last 30 days)
i want to scale my values which are in range of [0,360], [-1,1]to [0,1]

Answers (5)

Jan on 28 Aug 2017
Edited: Jan on 28 Aug 2017
The general method to scale any input array (vector, matrix, multi-dim array) to the range [0, 1] is:
maxV = max(V(:));
minV = min(V(:));
Vs = (V - minV) / (maxV - minV);

Jan on 16 Aug 2013
The following scales array x from any range to [0, 1]
scaled = x - min(x);
scaled = scaled / max(scaled);

Alireza Ahani
Alireza Ahani on 28 Feb 2021
check out this function. you can specify also the boundaries.
  1 Comment
Walter Roberson
Walter Roberson on 28 Feb 2021
This function did not exist back when the question was asked, but is a useful function to know now.
In older days, the deceptively named mat2gray() function was the one to call to do the rescaling.

Sign in to comment.

Azzi Abdelmalek
Azzi Abdelmalek on 16 Aug 2013
% you can use the same code for all cases

Abdullah Caliskan
Abdullah Caliskan on 14 Aug 2017
Edited: Walter Roberson on 28 Feb 2021
if input is matrix, you can use this. upper, bottom
xmax =max(input);
xmin =min(input);
  1 Comment
Jan on 28 Aug 2017
This works columnwise. I assume the min and max values should concern the complete matrix.

Sign in to comment.


Find more on Characters and Strings 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!