use rescale with matrix

2 次查看(过去 30 天)
shamal
shamal 2025-5-9
评论: shamal 2025-5-10
hi,i want to normalize matrix using interval -1 and 1
load('matlab_E');
B=rescale(E,1,-1);
Error using rescale>preprocessInputs (line 90)
Lower bound argument must be less than or equal to the upper bound argument.

Error in rescale (line 36)
[A, a, b, inputMin, inputMax] = preprocessInputs(A, varargin{:});

采纳的回答

Steven Lord
Steven Lord 2025-5-9
From the rescale documentation page: "R = rescale(A,l,u) scales all elements in A to the interval [l u]."
The second input argument must be less than or equal to the third input argument. In your call, that is not satisfied. Swap the order of the 1 and -1.
  8 个评论
Voss
Voss 2025-5-10
@Luca Re: Given:
have = [0 0.2 0.4 0.6 0.8 1];
min_to_get = 10;
max_to_get = 15;
Here's the math that does what you want:
min_have = min(have);
max_have = max(have);
to_get = (have-min_have)./(max_have-min_have).*(max_to_get-min_to_get)+min_to_get
to_get = 1×6
10 11 12 13 14 15
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Or, here's the MATLAB function call to do it:
to_get = rescale(have,min_to_get,max_to_get)
to_get = 1×6
10 11 12 13 14 15
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by