Cody

# Problem 1312. Rescaling vector

Solution 3402193

Submitted on 26 Oct 2020 by Sibi
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = [-2 -10 5 10]; a = 0; b = 1; assert(isequal(rescale_vector(x,a,b),[0.4 0 0.75 1]))

y = 0.4000 0 0.7500 1.0000

2   Pass
x = [-2 -10 5 10]; a = 1; b = 0; assert(isequal(rescale_vector(x,a,b),[0.6 1 0.25 0]))

y = 0.6000 1.0000 0.2500 0

3   Pass
x = rand(10,1); a = realmin; b = realmax/1e2; y = rescale_vector(x,a,b) assert(min(y)==realmin & max(y)==b)

y = 1.0e+306 * 1.7977 1.5273 0.9571 0.9138 1.1262 1.1411 1.3463 1.5411 1.0091 0.0000 y = 1.0e+306 * 1.7977 1.5273 0.9571 0.9138 1.1262 1.1411 1.3463 1.5411 1.0091 0.0000

4   Pass
x = diag(pascal(10)); a = -realmax/2; b = realmax/2; y = rescale_vector(x,a,b); assert(min(y)==a && max(y)==b)

y = 1.0e+307 * -8.9885 -8.9881 -8.9866 -8.9814 -8.9630 -8.8957 -8.6472 -7.7198 -4.2301 8.9885

### Community Treasure Hunt

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

Start Hunting!