Cody

# Problem 801. Construct an index vector from two input vectors in vectorized fashion

Solution 3180401

Submitted on 12 Oct 2020 by Li Ding
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
x1 = 1; x2 = 5; y_correct = [1:5]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

2   Pass
x1 = [7 10 13]; x2 = [9 12 15]; y_correct = [7:15]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

y = 7 8 9 10 11 12 y = 7 8 9 10 11 12 13 14 15

3   Pass
x1 = [13 7]; x2 = [15 9]; y_correct = [13 14 15 7 8 9]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

y = 13 14 15 7 8 9

4   Pass
x1=[1:5:5000];x2=[4:5:5000];y_correct=setdiff([1:5000],[5:5:5000]); assert( isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

y = 1 2 3 4 6 7 8 9 y = 1 2 3 4 6 7 8 9 11 12 13 14 y = 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 y = 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 y = 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 y = 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 32 38 39 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 36 38 39 41 42 43 44 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 40 38 39 41 42 43 44 46 47 48 49 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 44 38 39 41 42 43 44 46 47 48 49 51 52 53 54 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 48 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 52 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 56 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 64 76 77 78 79 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 68 76 77 78 79 81 82 83 84 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 72 76 77 78 79 81 82 83 84 86 87 88 89 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 76 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 80 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 84 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 88 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106 107 108 109 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 90 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106 107 108 109 111 112 Columns 91 through 92 113 114 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 90 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106 107 108 109 111 112 Columns 91 through 96 113 114 116 117 118 119 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 90 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106 107 108 109 111 112 Columns 91 through 100 113 114 116 117 118 119 121 122 123 124 y = Columns 1 through 30 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 Columns 31 through 60 38 39 41 42 43 44 46 47 48 49 51 52 53 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 Columns 61 through 90 76 77 78 79 81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106 107 108 109 111 112 Columns 91 through 104 113 114 116 117 118 119 121 122 123 124 126 127 128 129 y = Columns 1 through...

### Community Treasure Hunt

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

Start Hunting!