use rescale with matrix

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{:});

 Accepted Answer

Steven Lord
Steven Lord on 9 May 2025
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 Comments

excuse me..it's possible to reconvert normalize series in the original series?
I'm not sure I understand what you're asking. Are you asking if you can take the output of rescale and reverse the scaling to obtain the original array again? That would depend on whether or not you have some additional information about your original array.
x1 = [1 2 3 4 5]
x1 = 1×5
1 2 3 4 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x2 = x1 + 100
x2 = 1×5
101 102 103 104 105
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
R1 = rescale(x1, 0, 1)
R1 = 1×5
0 0.2500 0.5000 0.7500 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
R2 = rescale(x2, 0, 1)
R2 = 1×5
0 0.2500 0.5000 0.7500 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
isequal(R1, R2)
ans = logical
1
Without any additional information, if I gave you R1 (which is the same as R2), how could you tell me if the original array was x1 or x2?
shamal
shamal on 9 May 2025
Edited: shamal on 9 May 2025
example: (look pics)
I need to calculate boolinger band (stdev) in series
to do this i want do normalize series and after i calculate boolinger band
Now i want to plot the band stdev but it's normalize, then i must to convert series normalize in series not normalize
in imagine.png you see original series and the boolinger Not nornalized
if i normalize series and calculate boolinger band using normalized i see a band in interval -1 1 and i don't plot it..
i must to reconvert to plot it
shamal
shamal on 9 May 2025
Edited: shamal on 9 May 2025
you write : "Without any additional information, if I gave you R1 (which is the same as R2), how could you tell me if the original array was x1 or x2?"
I 've information about the max and min of series and i can use it to reconvert series
Okay, so you want to rescale other data using the same scaling factors that were used on the original data? In that case perhaps the normalize function is what you want. Let's say I normalize a vector to cover the range [0, 1] and I ask for three outputs.
x = 10:15;
[y1, c, s] = normalize(x, "range")
y1 = 1×6
0 0.2000 0.4000 0.6000 0.8000 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
c = 10
s = 5
Now if I normalize one of the data points in x (without the rest) and use the outputs from the first normalize call I ought to get essentially the same value as the element in y1 corresponding to that data point in x.
y2 = normalize(x(4), "center", c, "scale", s) % ought to be essentially y1(4)
y2 = 0.6000
difference = y1(4)-y2 % essentially 0
difference = 1.1102e-16
shamal
shamal on 10 May 2025
Edited: shamal on 10 May 2025
ok thank you but if i've this serie normalize "0 0,2000 0,4000 0,6000 0,8000 1,0000"
i want to get :"10 11 12 13 14 15"
it's possibile? I didn't see this in your steps
@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>

Thank you

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2024b

Asked:

on 9 May 2025

Commented:

on 10 May 2025

Community Treasure Hunt

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

Start Hunting!