Cody

# Problem 1312. Rescaling vector

Solution 3918553

Submitted on 30 Nov 2020 by Soobok
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]))

x = 8 0 15 20 x = 0.4000 0 0.7500 1.0000 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]))

x = 8 0 15 20 x = 0.4000 0 0.7500 1.0000 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)

x = 0.8137 0.0052 0.5686 0.8137 0 0.4088 0.4243 0.7341 0.8531 0.3953 x = 0.9538 0.0061 0.6665 0.9538 0 0.4792 0.4973 0.8605 1.0000 0.4634 y = 1.0e+306 * 1.7146 0.0109 1.1982 1.7147 0.0000 0.8615 0.8941 1.5469 1.7977 0.8331 y = 1.0e+306 * 1.7146 0.0109 1.1982 1.7147 0.0000 0.8615 0.8941 1.5469 1.7977 0.8331

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)

x = 0 1 5 19 69 251 923 3431 12869 48619 x = 0 0.0000 0.0001 0.0004 0.0014 0.0052 0.0190 0.0706 0.2647 1.0000 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!