[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #56639] rescale: new function to scale an arra
From: |
Markus Mützel |
Subject: |
[Octave-bug-tracker] [bug #56639] rescale: new function to scale an array to match a given interval |
Date: |
Mon, 2 Dec 2019 02:51:02 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0 |
Follow-up Comment #11, bug #56639 (project octave):
You are right. What about the following change?
diff -r 80d68a3e8ec0 scripts/general/rescale.m
--- a/scripts/general/rescale.m Mon Dec 02 01:16:12 2019 -0600
+++ b/scripts/general/rescale.m Mon Dec 02 08:42:28 2019 +0100
@@ -85,13 +85,13 @@
inmax = max (A(:));
endif
- ## Truncate values in A
- A(A < inmin) = inmin;
- A(A > inmax) = inmax;
-
## Rescale A to interval [l,u] in range interval [inmin,inmax].
B = l + ( (A - inmin) ./ (inmax - inmin) ) .* (u - l);
+ ## Truncate values
+ B(A < inmin) = l;
+ B(A > inmax) = u;
+
endfunction
%!assert (rescale (0:5), (0:5)/5)
The input checks could probably be more restrictive, too. The following typo
e.g. doesn't trigger an error:
rescale (0:6, "inptumin", 1)
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?56639>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/