Need help understanding rescale()

조회 수: 20 (최근 30일)
Adrian Velasquez
Adrian Velasquez 2022년 8월 1일
댓글: Adrian Velasquez 2022년 8월 2일
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에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by