Cody

Problem 1041. Find Index of maximum Value and maximum Value of a vector

Solution 1598994

Submitted on 3 Aug 2018 by Srishti Saha
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
seq=randi(5,1,10); seq_max = max(seq); seq_idx= find(seq==seq_max,1,'first'); [max_val, max_idx] = max_val_idx(seq); assert(isequal(max_val,seq_max)); assert(isequal(max_idx,seq_idx));

x = 5 3 4 5 2 4 1 3 4 5 max_val1 = 5 max_idx1 = 1

2   Pass
seq=rand(10); seq_max = max(seq(:)); seq_idx= find(seq==seq_max,1,'first'); [max_val, max_idx] = max_val_idx(seq); assert(isequal(max_val,seq_max)); assert(isequal(max_idx,seq_idx));

x = 0.8716 0.5378 0.7140 0.8143 0.1305 0.8363 0.4179 0.8690 0.0735 0.3209 0.9109 0.1306 0.8091 0.8350 0.9186 0.7542 0.4688 0.2335 0.9728 0.8008 0.7958 0.8018 0.7616 0.2275 0.1848 0.6942 0.0681 0.3766 0.3953 0.5517 0.2666 0.3462 0.0041 0.6738 0.9935 0.2703 0.9054 0.3557 0.6326 0.2538 0.2108 0.9843 0.0090 0.9598 0.4563 0.9815 0.1395 0.9421 0.8881 0.6302 0.5296 0.2576 0.7750 0.1494 0.2193 0.8405 0.1415 0.9351 0.6528 0.5353 0.6710 0.1690 0.2380 0.2172 0.3883 0.0800 0.1832 0.6549 0.6260 0.6956 0.5309 0.4029 0.7838 0.8132 0.6462 0.0785 0.0739 0.0856 0.6426 0.8832 0.5348 0.9047 0.8084 0.2414 0.8936 0.9891 0.5952 0.7783 0.0717 0.5177 0.8040 0.8331 0.2965 0.1741 0.7356 0.6323 0.7052 0.7899 0.9816 0.4057 max_val1 = 0.9935 max_idx1 = 35

3   Pass
seq=randn(10); seq_max = max(seq(:)); seq_idx= find(seq==seq_max,1,'first'); [max_val, max_idx] = max_val_idx(seq); assert(isequal(max_val,seq_max)); assert(isequal(max_idx,seq_idx));

x = -1.5948 -1.0145 0.4791 0.6402 -0.8572 -0.0668 1.7915 0.9974 1.7797 0.0868 -0.4319 -0.2367 -1.1901 0.9494 1.0416 0.6270 -1.0720 0.5818 -0.2731 -2.1353 0.2143 -1.5904 -0.8006 -0.0127 0.0036 1.5935 0.3769 0.3294 0.8455 0.2642 -0.5128 -0.4140 0.1148 0.4382 -0.4961 0.5497 1.9011 1.0984 1.5251 -0.6389 0.4155 0.4087 -0.2622 0.3291 0.1178 1.0076 0.7400 -1.6047 2.3781 0.2471 1.2393 -0.7923 0.1353 0.9480 0.3903 0.5807 1.1966 -0.2182 0.5907 -0.1811 1.3851 0.2154 -0.4668 0.4873 -0.1782 2.3281 0.8280 0.4340 -0.4218 -0.9088 -2.0966 -0.7776 -0.5338 -1.6161 0.9754 1.8551 -0.6894 -1.3621 0.8524 0.2852 0.7663 -1.8274 0.3382 -0.5199 0.2791 0.6863 0.0964 -0.0698 0.7264 -0.3125 0.5498 -1.2753 1.1349 0.8552 -0.3193 -0.1641 0.3807 -1.9327 -0.7125 0.6665 max_val1 = 2.3781 max_idx1 = 49

4   Pass
seq=randi(2^15,128,1); seq_max = max(seq(:)); seq_idx= find(seq==seq_max,1,'first'); [max_val, max_idx] = max_val_idx(seq); assert(isequal(max_val,seq_max)); assert(isequal(max_idx,seq_idx));

x = 5082 5846 14353 10492 13568 32538 27332 25476 24092 283 22299 9172 8343 2103 1376 14404 32617 13940 10880 4694 22641 14472 16902 24642 10542 12565 23926 21198 21697 20413 28879 23049 22735 3488 22458 6330 26662 4164 5717 28904 6046 20333 15834 13298 11089 10014 22032 7441 118 2926 29474 9465 4256 29428 10874 5579 26523 2341 2470 8405 6112 5041 15806 14576 31616 2236 10320 8891 17304 15052 17290 26574 20081 22746 16596 4418 27761 25530 20376 26837 4425 32416 13010 2009 30443 27548 25732 32168 8905 10724 18692 16176 4909 617 31499 15283 13890 32060 7796 2768 1720 26505 13637 253 8561 21660 7500 20828 25456 32364 18574 1049 3560 31334 30753 10543 8859 28525 25323 31220 16412 15485 16510 26563 2855 3578 4049 19294 max_val1 = 32617 max_idx1 = 17

Suggested Problems

More from this Author246

Community Treasure Hunt

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

Start Hunting!