Need help understanding rescale()

20 次查看(过去 30 天)
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

采纳的回答

Jeffrey Clark
Jeffrey Clark 2022-8-1
@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 个评论
Adrian Velasquez
Adrian Velasquez 2022-8-2
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by