Cody

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

Solution 2394149

Submitted on 27 May 2020 by Nikolaos Nikolaou
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|)')) )

t = 1 2 3 4 5 y = 1 2 3 4 5 ans = []

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

t = 7 8 9 y = 7 8 9 t = 10 11 12 y = 7 8 9 10 11 12 t = 13 14 15 y = 7 8 9 10 11 12 13 14 15 ans = []

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

t = 13 14 15 y = 13 14 15 t = 7 8 9 y = 13 14 15 7 8 9 ans = []

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

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

### Community Treasure Hunt

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

Start Hunting!