Need help understanding rescale()

9 views (last 30 days)
I have an array x that I'm running rescale on. However, I'm not understanding the output that I'm getting. Should it not be [1.000 0.9000 0.9500 0.9500; 0.7000, ect] I'm not sure if it's a problem with my code or my understanding of how rescale() works. Any tips help. Thank!
function X = rescale_scores()
x = [100 90 95 95; 70 50 60 60; 80 70 90 80]
[m,n] = size(x);
A = rescale(x)
end
% OUTPUT THAT I'M GETTING
x =
100 90 95 95
70 50 60 60
80 70 90 80
A =
1.0000 0.8000 0.9000 0.9000
0.4000 0 0.2000 0.2000
0.6000 0.4000 0.8000 0.6000

Accepted Answer

Jeffrey Clark
Jeffrey Clark on 1 Aug 2022
@Adrian Velasquez, according to rescale documentation each element should be rescaled to [0..1] using this method:
l + [(A-inmin)./(inmax-inmin)].*(u-l)
to scale the elements of an array A when the values of A are within the bounds of inmin and inmax.
  • If l and u are not specified, then rescale uses the default values 0 and 1, respectively.
  • If the 'InputMin' name-value pair is not specified, then rescale sets its value to the default min(A(:)).
  • If the 'InputMax' name-value pair is not specified, then rescale sets its value to the default max(A(:)).
In your case since l = 0, u = 1, InputMin = min(x(:)) and InputMax = max(x(:) it becomes:
0+[(x-50)./(100-50)].*(1-0) == (x-50)/50 ==> 100 becomes 1, 50 becomes 0 and so on.
So rescale works as advertised.
  1 Comment
Adrian Velasquez
Adrian Velasquez on 2 Aug 2022
Yes that makes sense! I didn't realize that the minimum defaulted to the minimum of the input if it is not explicitely specified. Thanks for the help!

Sign in to comment.

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!