Need help understanding rescale()

18 visualizaciones (últimos 30 días)
Adrian Velasquez
Adrian Velasquez el 1 de Ag. de 2022
Comentada: Adrian Velasquez el 2 de Ag. de 2022
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

Respuesta aceptada

Jeffrey Clark
Jeffrey Clark el 1 de Ag. de 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 comentario
Adrian Velasquez
Adrian Velasquez el 2 de Ag. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by