Need help understanding rescale()

17 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jeffrey Clark
Jeffrey Clark il 1 Ago 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 Commento
Adrian Velasquez
Adrian Velasquez il 2 Ago 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!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by