Cody

Problem 1273. Max index of 3D array

Solution 2884457

Submitted on 27 Aug 2020 by Pauli Huusari
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 = zeros(10,10,10); x(5,5,5) = 10; y_correct = [5,5,5]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 10 second_dimension_area = 100 correct_two_dimension = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 max_columns = 0 0 0 0 10 0 0 0 0 0 max_rows = 0 0 0 0 10 0 0 0 0 0 m = 10 x = 5 m = 10 y_1 = 5 y = 5 5 5

2   Pass
x = randn(10,10,10); x(7,5,8) = 11; y_correct = [7,5,8]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 11 second_dimension_area = 100 correct_two_dimension = -0.7210 -0.5652 -2.0121 -0.4401 1.2433 0.1593 0.2343 -0.4074 -3.4355 1.4335 0.4307 0.6413 -0.4629 1.2620 2.8658 -0.5140 -1.1574 1.7640 -0.4481 -0.8223 -1.5210 0.4475 0.7839 -0.2680 0.9048 -1.2844 -0.0989 -1.5509 -1.1318 -1.3468 1.2591 -1.1412 0.4111 -1.4690 -0.3689 -1.1823 0.1441 -0.9432 0.2380 -0.6524 -0.7342 -0.0034 -1.8647 -1.1752 -1.3881 0.1675 1.8938 -0.2672 -1.4364 0.5035 1.8833 -0.2526 0.7620 0.0180 -0.6384 0.3580 1.1129 0.1535 0.9415 0.4143 -1.0668 -0.4131 0.1514 0.1650 11.0000 -1.5553 0.2471 -0.3358 -0.0366 -1.8748 0.8046 -1.2526 1.3417 2.1950 0.6421 -0.6616 -1.0317 0.6908 0.2144 0.3205 0.9485 1.1691 1.4124 0.7529 1.7701 -0.2603 1.0538 -0.2786 1.4255 -0.4300 0.5690 0.0073 -1.5094 0.1206 0.0611 -0.7625 0.8747 -0.1969 -0.2356 1.8701 max_columns = 1.8833 1.1691 1.4124 2.1950 11.0000 0.3580 1.8938 1.7640 1.4255 1.8701 max_rows = 1.4335 2.8658 0.9048 1.2591 1.8938 1.8833 11.0000 2.1950 1.7701 1.8701 m = 11 x = 7 m = 11 y_1 = 5 y = 7 5 8

3   Pass
x = randn(10,10,100); x(10,5,8) = 99; y_correct = [10,5,8]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 99 second_dimension_area = 100 correct_two_dimension = 0.1865 0.4674 1.4617 -1.3528 -1.5062 0.9399 1.0491 -0.6312 -1.7303 -0.9168 -0.0478 0.1223 -0.4828 1.0043 1.3394 -0.6143 -1.8284 0.7955 -0.4893 -1.9517 -0.8245 0.4066 -0.1950 -0.5255 -0.4741 0.9648 0.7240 0.4165 0.8525 -0.0111 -0.9340 -0.0658 1.8302 -0.3787 -0.8130 -0.3514 1.1340 -0.0092 -1.2922 -0.2293 -1.2643 -0.8740 -0.4890 -0.7763 -0.4956 1.4587 -0.0852 -0.9372 0.9031 0.6289 1.4232 -0.1617 -0.0884 0.4762 -0.7413 -1.8243 -1.3997 -2.0183 -1.2445 0.5218 -1.4551 -0.0640 0.6503 0.3379 0.2458 0.5612 -0.1430 0.1600 0.7203 0.0783 -0.3731 -2.4754 2.1362 -0.7269 0.2719 -0.9237 -0.7707 -0.6498 0.9577 0.0620 0.9269 -2.3401 3.0875 -0.7124 -0.2190 -0.9857 1.4528 1.7709 0.1966 -1.1292 -0.2295 -0.0052 -0.4500 -0.7861 99.0000 -0.0646 0.9467 -0.3923 -1.1179 0.5869 max_columns = 1.4232 0.4674 3.0875 1.0043 99.0000 1.4587 1.4528 1.7709 0.9577 0.6289 max_rows = 1.4617 1.3394 0.9648 1.8302 1.4587 1.4232 0.7203 2.1362 3.0875 99.0000 m = 99 x = 10 m = 99 y_1 = 5 y = 10 5 8

4   Pass
x = randn(10,10,10); x(1,3,7) = 42; y_correct = [1,3,7]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 42 second_dimension_area = 100 correct_two_dimension = 1.9256 0.3498 42.0000 -0.4241 -1.0351 1.0425 0.1200 0.7162 -1.8308 1.4063 -0.2044 0.1572 2.0999 -0.0603 -1.1761 -1.3761 -0.7110 2.1150 2.5796 0.3082 -1.3663 0.2133 0.6988 -0.2813 -0.0765 0.2137 0.0505 -0.1912 -0.9924 1.6268 -0.5814 -0.2331 1.5098 0.7085 0.7783 0.3592 -0.4520 0.8546 -2.1028 0.0047 0.2429 0.0856 0.4780 -0.1746 0.9881 1.5140 -1.2168 1.1471 2.3893 1.3566 1.0830 -0.0725 -0.5282 0.7139 -1.2926 -0.8424 -0.5299 -0.4445 0.2378 -0.6991 1.5805 -0.4365 -0.2880 -0.0108 -0.8481 -0.0894 -0.1614 -0.9172 2.2221 0.0959 0.2094 -2.2458 -0.8945 1.5144 -1.8082 0.3585 0.1396 0.0673 -0.2447 1.5293 -0.4045 -0.3859 -1.2561 1.4422 1.3043 -1.6581 0.1355 -1.1592 -0.0066 -0.7875 -0.6277 -1.4128 0.7611 -0.4010 -0.4109 1.2188 0.6263 -0.0920 0.4981 0.1569 max_columns = 1.9256 0.3498 42.0000 1.5144 1.3043 1.5140 0.6263 2.1150 2.5796 1.6268 max_rows = 42.0000 2.5796 1.6268 1.5098 2.3893 1.0830 2.2221 1.5293 1.4422 1.2188 m = 42 x = 1 m = 42 y_1 = 3 y = 1 3 7

5   Pass
x = randn(10,10,100); x(4,4,7) = 123456789; y_correct = [4,4,7]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 123456789 second_dimension_area = 100 correct_two_dimension = 1.0e+08 * -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 1.2346 -0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 max_columns = 1.0e+08 * 0.0000 0.0000 0.0000 1.2346 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 max_rows = 1.0e+08 * 0.0000 0.0000 0.0000 1.2346 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 m = 123456789 x = 4 m = 123456789 y_1 = 4 y = 4 4 7

6   Pass
x = randn(10,10,10); x(1,1,9) = 10701; y_correct = [1,1,9]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 10701 second_dimension_area = 100 correct_two_dimension = 1.0e+04 * 1.0701 0.0000 -0.0002 -0.0001 0.0001 -0.0000 -0.0001 -0.0000 0.0002 0.0000 -0.0000 -0.0001 -0.0001 0.0000 0.0001 0.0000 -0.0002 -0.0000 -0.0002 -0.0001 0.0001 0.0001 0.0000 -0.0000 0.0001 -0.0001 0.0001 -0.0002 -0.0001 -0.0000 0.0001 -0.0000 0.0000 0.0002 -0.0001 0.0001 0.0000 0.0002 -0.0001 0.0003 0.0001 0.0001 0.0001 -0.0001 -0.0001 0.0001 -0.0001 -0.0002 -0.0000 0.0001 0.0002 0.0000 -0.0000 -0.0000 0.0000 0.0001 0.0001 0.0000 -0.0002 0.0001 0.0002 0.0002 0.0001 -0.0001 0.0001 0.0001 0.0001 -0.0000 -0.0000 0.0000 -0.0002 -0.0001 -0.0000 -0.0001 -0.0000 0.0001 0.0000 -0.0001 -0.0001 -0.0002 -0.0000 0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0002 0.0001 -0.0001 0.0001 0.0000 0.0001 0.0001 0.0000 0.0000 0.0001 -0.0000 0.0000 max_columns = 1.0e+04 * 1.0701 0.0002 0.0001 0.0002 0.0001 0.0001 0.0001 0.0002 0.0002 0.0003 max_rows = 1.0e+04 * 1.0701 0.0001 0.0001 0.0003 0.0001 0.0002 0.0002 0.0001 0.0001 0.0001 m = 10701 x = 1 m = 10701 y_1 = 1 y = 1 1 9

7   Pass
x = randn(10,10,100); x(1,7,3) = 10701; y_correct = [1,7,3]; assert(isequal(Index_Max3d(x),y_correct))

max_value = 10701 second_dimension_area = 100 correct_two_dimension = 1.0e+04 * 0.0000 -0.0001 -0.0003 0.0001 -0.0002 -0.0000 1.0701 0.0000 -0.0000 -0.0002 0.0001 0.0001 -0.0001 0.0001 -0.0001 -0.0002 0.0002 -0.0000 -0.0000 -0.0001 -0.0000 0.0000 0.0000 0.0001 -0.0001 0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0000 -0.0001 0.0001 0.0000 0.0000 0.0001 -0.0000 -0.0001 -0.0001 0.0001 0.0000 -0.0001 0.0001 -0.0000 0.0001 0.0001 0.0001 -0.0000 -0.0001 -0.0003 0.0000 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 -0.0001 -0.0000 -0.0002 -0.0001 0.0000 -0.0001 0.0002 0.0001 0.0001 -0.0001 -0.0001 0.0000 0.0001 -0.0001 0.0000 0.0002 -0.0000 0.0001 0.0002 0.0000 -0.0001 -0.0001 -0.0000 -0.0000 0.0001 -0.0001 -0.0000 0.0001 -0.0001 -0.0001 0.0001 -0.0001 -0.0001 -0.0002 -0.0000 -0.0000 -0.0001 0.0001 -0.0000 -0.0001 0.0001 -0.0000 max_columns = 1.0e+04 * 0.0001 0.0001 0.0001 0.0002 0.0002 0.0001 1.0701 0.0001 0.0001 0.0001 max_rows = 1.0e+04 * 1.0701 0.0002 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0001 0.0001 m = 10701 x = 1 m = 10701 y_1 = 7 y = 1 7 3

Suggested Problems

More from this Author2

Community Treasure Hunt

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

Start Hunting!