Cody

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

Solution 1701775

Submitted on 3 Jan 2019 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
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));

seq = 3 2 1 4 4 2 2 2 1 2

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));

seq = 0.8557 0.1700 0.0304 0.5685 0.1655 0.9616 0.9737 0.4355 0.2527 0.5958 0.9905 0.6310 0.6366 0.4023 0.9483 0.6064 0.8708 0.2756 0.6044 0.0059 0.9583 0.1337 0.3465 0.9025 0.5706 0.5305 0.8748 0.4154 0.9946 0.5969 0.5389 0.1870 0.7257 0.5057 0.9457 0.3997 0.6030 0.0012 0.2866 0.6605 0.3700 0.6732 0.7310 0.8016 0.3286 0.2345 0.6031 0.2390 0.9334 0.9975 0.9538 0.6954 0.5232 0.3241 0.0835 0.1582 0.7229 0.5178 0.3459 0.2556 0.9992 0.3750 0.8878 0.7324 0.1014 0.7445 0.9380 0.2754 0.0946 0.3051 0.8799 0.1186 0.5877 0.2163 0.8376 0.6966 0.3261 0.5408 0.4169 0.4549 0.3938 0.8249 0.3896 0.4282 0.9982 0.7022 0.9657 0.0143 0.1036 0.3120 0.8621 0.3569 0.8645 0.9553 0.0634 0.5273 0.0264 0.8601 0.1008 0.5765

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));

seq = 0.4279 0.0961 1.0817 0.9444 -1.0545 -1.1152 -0.0012 -2.3331 0.5526 0.3599 1.0486 0.7767 0.3234 1.5246 -1.2078 1.0359 -1.0103 0.2730 0.3784 0.4861 -0.2669 -0.3440 1.5726 -1.1659 0.6174 -1.4618 0.5988 0.4394 -0.1050 0.1532 -0.3876 0.8998 -0.6606 0.4405 0.5541 -1.6830 0.7976 0.6384 -1.7973 -0.8005 -0.4885 -1.2489 0.5264 1.1952 0.1747 -1.1147 -0.9612 -1.2686 -2.3225 0.3655 -0.0214 -0.4060 -0.3989 -1.0192 0.7283 0.5235 0.5971 0.8254 0.4297 -0.8084 -0.9006 -0.0976 -0.8567 0.4753 -0.6125 -0.9238 0.0004 0.2190 -0.4037 -0.7713 1.4912 1.1884 0.2812 1.9357 -0.6632 0.6217 1.1092 -1.0224 0.7377 -1.0462 -1.1453 0.5894 -2.3146 0.9595 -0.6062 1.0883 0.1321 -0.0324 -1.1862 -1.2075 -0.7461 -0.0606 2.1011 -1.2954 1.6987 -0.1387 0.0314 1.2418 0.8731 -0.0468

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));

seq = 10902 14869 13245 9800 27000 22671 11573 6567 28057 288 10732 10387 24040 13973 18953 26070 31808 24708 28077 16463 15398 19496 23933 6197 31180 7434 27298 28019 8728 31776 20886 10482 544 26049 31997 25677 15393 6465 25950 15479 11332 29330 27107 26929 21712 23002 27672 22373 591 26120 12849 8274 23798 17642 9098 8347 20754 29688 17787 3778 8379 9061 323 25186 29365 26733 13747 20799 28860 8385 2028 20106 4879 5257 4638 9749 9655 3511 23244 18786 25134 18766 22876 29369 14344 17964 19775 16854 27028 27584 18296 9734 28677 18523 26407 17576 18598 18946 7574 8168 28709 18307 24909 14490 7865 23477 26315 27815 5830 1201 6540 18544 3057 21900 2497 11286 15589 28150 13031 29603 30829 11475 589 5057 1659 15914 2089 19308

### Community Treasure Hunt

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

Start Hunting!