Cody

Problem 45409. MinMax mapping

Solution 2194371

Submitted on 6 Apr 2020 by Martin C.
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 5 10]; y =[1, 1.375, 2]; assert(isequal(minmax_map(x,1,2),y))

maxi = 10 mini = 2 y = 0.2500 0.6250 1.2500 y = 1.0000 1.3750 2.0000

2   Pass
x=[-5 3 -65 -55 34 555 3 2 0 -5]; y =[ 187.1 198.71 100 114.52 243.71 1000 198.71 197.26 194.35 187.1]; z=abs(minmax_map(x,100,1000)-y)<0.01 assert(all(z))

maxi = 555 mini = -65 y = -7.2581 4.3548 -94.3548 -79.8387 49.3548 805.6452 4.3548 2.9032 0 -7.2581 y = 1.0e+03 * 0.1871 0.1987 0.1000 0.1145 0.2437 1.0000 0.1987 0.1973 0.1944 0.1871 z = 1×10 logical array 1 1 1 1 1 1 1 1 1 1

3   Pass
x = magic(3); y =[24 3 18 9 15 21 12 27 6]; assert(isequal(minmax_map(x,3,27),y))

maxi = 9 mini = 1 y = 24 3 18 9 15 21 12 27 6 y = 24 3 18 9 15 21 12 27 6

4   Pass
x = pascal(5); y =[-100 -100 -100 -100 -100 -100 -97.101 -94.203 -91.304 -88.406 -100 -94.203 -85.507 -73.913 -59.42 -100 -91.304 -73.913 -44.928 -1.4493 -100 -88.406 -59.42 -1.4493 100]; z=abs(minmax_map(x,-100,100)-y)<0.01 assert(all(z,'all'))

maxi = 70 mini = 1 y = 2.8986 2.8986 2.8986 2.8986 2.8986 2.8986 5.7971 8.6957 11.5942 14.4928 2.8986 8.6957 17.3913 28.9855 43.4783 2.8986 11.5942 28.9855 57.9710 101.4493 2.8986 14.4928 43.4783 101.4493 202.8986 y = -100.0000 -100.0000 -100.0000 -100.0000 -100.0000 -100.0000 -97.1014 -94.2029 -91.3043 -88.4058 -100.0000 -94.2029 -85.5072 -73.9130 -59.4203 -100.0000 -91.3043 -73.9130 -44.9275 -1.4493 -100.0000 -88.4058 -59.4203 -1.4493 100.0000 z = 5×5 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

5   Pass
x=eye(5); y=[55 5 5 5 5 5 55 5 5 5 5 5 55 5 5 5 5 5 55 5 5 5 5 5 55]; assert(isequal(minmax_map(x,5,55),y))

maxi = 1 mini = 0 y = 50 0 0 0 0 0 50 0 0 0 0 0 50 0 0 0 0 0 50 0 0 0 0 0 50 y = 55 5 5 5 5 5 55 5 5 5 5 5 55 5 5 5 5 5 55 5 5 5 5 5 55

6   Pass
x=[4 -5 -55 -555 34; 34 34 34 -66 2]; y=[1.4745 1.4669 1.4244 1 1.5 1.5 1.5 1.5 1.4151 1.4728] z=abs(minmax_map(x,1,1.5)-y)<0.01 assert(all(z,'all'))

y = 1.4745 1.4669 1.4244 1.0000 1.5000 1.5000 1.5000 1.5000 1.4151 1.4728 maxi = 34 mini = -555 y = 0.0034 -0.0042 -0.0467 -0.4711 0.0289 0.0289 0.0289 0.0289 -0.0560 0.0017 y = 1.4745 1.4669 1.4244 1.0000 1.5000 1.5000 1.5000 1.5000 1.4151 1.4728 z = 2×5 logical array 1 1 1 1 1 1 1 1 1 1

Suggested Problems

More from this Author149

Community Treasure Hunt

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

Start Hunting!