Cody

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

Solution 2848284

Submitted on 18 Aug 2020 by Ramesh Kumar V
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));

m = 5 5 4 4 4 3 2 2 1 1 n = 1 2 3 8 10 5 6 7 4 9 max_val = 5 max_idx = 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));

m = 0.9972 0.9960 0.9895 0.9789 0.9782 0.9709 0.9509 0.9390 0.9306 0.9179 0.9109 0.9085 0.8939 0.8850 0.8835 0.8791 0.8752 0.8751 0.8734 0.8677 0.8624 0.8552 0.8532 0.8192 0.8144 0.7951 0.7844 0.7830 0.7339 0.7256 0.7225 0.7086 0.7008 0.6897 0.6854 0.6791 0.6731 0.6703 0.6600 0.6390 0.6340 0.6196 0.6175 0.5938 0.5553 0.5307 0.5284 0.5194 0.5114 0.5088 0.5075 0.4990 0.4958 0.4662 0.4615 0.4513 0.4394 0.4362 0.4256 0.4193 0.4061 0.4040 0.3909 0.3747 0.3734 0.3729 0.3678 0.3655 0.3536 0.3212 0.3181 0.3096 0.3068 0.2919 0.2861 0.2537 0.2293 0.2291 0.2187 0.2110 0.1898 0.1652 0.1572 0.1502 0.1360 0.1322 0.1309 0.1280 0.1253 0.1252 0.1100 0.1070 0.1064 0.1035 0.0956 0.0897 0.0629 0.0531 0.0433 0.0014 n = 64 59 95 8 10 96 38 47 86 57 82 83 1 97 92 55 99 67 19 31 50 48 88 25 65 22 45 4 79 32 49 17 11 53 41 63 12 98 26 73 62 27 46 69 42 7 14 70 72 51 100 21 29 85 76 44 91 3 18 43 28 30 78 90 2 89 16 40 58 77 66 54 9 6 36 35 93 52 23 56 5 60 87 71 34 80 61 39 94 15 74 24 13 81 84 75 20 37 68 33 max_val = 0.9972 max_idx = 64

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

m = 2.3544 2.0021 1.9478 1.9039 1.8720 1.6078 1.6059 1.4606 1.3315 1.2482 1.1339 1.0865 1.0424 1.0076 0.9707 0.9404 0.8888 0.8725 0.8445 0.8411 0.7290 0.7130 0.7081 0.6213 0.6161 0.5669 0.5524 0.5305 0.4730 0.4523 0.4488 0.4450 0.4346 0.4171 0.3973 0.3333 0.3038 0.2663 0.2517 0.2357 0.2105 0.1053 0.0608 0.0508 0.0014 -0.0102 -0.0154 -0.0400 -0.0571 -0.0600 -0.0734 -0.0957 -0.1171 -0.1316 -0.1783 -0.1831 -0.1851 -0.2035 -0.2377 -0.3409 -0.3696 -0.3742 -0.3806 -0.3865 -0.4249 -0.4284 -0.4950 -0.6017 -0.6046 -0.6110 -0.6371 -0.6600 -0.6854 -0.7521 -0.7714 -0.8243 -0.8389 -0.9191 -0.9583 -0.9660 -1.0870 -1.0940 -1.1759 -1.2572 -1.2590 -1.3047 -1.3686 -1.3767 -1.4305 -1.4379 -1.5007 -1.5116 -1.5425 -1.5929 -1.7500 -1.7862 -1.7957 -1.9679 -2.2962 -2.7078 n = 92 68 44 51 81 76 19 16 84 79 7 39 65 74 35 50 42 37 77 36 59 14 97 100 17 75 86 53 8 45 52 94 72 4 47 67 71 27 64 78 80 33 66 93 20 22 96 41 25 23 54 31 91 95 5 38 29 85 98 3 88 30 89 2 40 55 49 11 62 82 73 48 57 83 87 99 56 15 90 32 43 1 28 10 61 13 63 21 69 9 46 18 24 26 58 70 60 6 34 12 max_val = 2.3544 max_idx = 92

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

m = 32706 32442 31864 31742 31358 31198 31017 30125 29565 28646 28572 28305 28278 28187 28085 27630 27505 27407 26805 26513 26499 26359 26162 24942 24778 24681 24011 23866 23513 23048 22416 22035 21917 21887 21527 21425 21242 21224 20791 20087 19897 19783 19669 18693 18616 18512 18083 18027 17883 16900 16564 16260 16144 16028 15918 15747 15747 15591 15323 15268 14974 14658 14439 14107 14016 13194 13009 13006 12944 12669 12645 12412 12192 11745 11603 11200 11122 10832 10607 10589 10547 10402 10143 9996 9937 9718 9651 9537 9486 9331 9144 8744 8673 8609 8510 7995 7794 7646 7386 7063 6769 6168 6028 5990 5849 5279 4875 4436 4002 3762 3653 3492 3482 3457 3222 2624 2548 2162 1887 1841 1840 1839 1701 930 830 794 182 155 n = 95 19 116 58 88 97 4 50 3 69 67 53 72 42 52 79 47 73 121 127 76 82 114 93 41 28 7 96 27 12 90 21 55 1 106 128 86 26 66 94 65 109 112 24 92 120 49 5 85 40 43 102 101 75 14 11 35 70 115 60 31 30 100 125 68 57 110 107 124 77 39 84 13 126 63 113 20 123 59 36 71 80 37 56 46 61 2 99 6 9 33 23 54 111 38 17 89 45 29 108 81 122 22 105 62 25 10 16 119 32 8 48 34 87 91 83 64 103 51 98 104 117 15 74 44 118 18 78 max_val = 32706 max_idx = 95

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!