Cody

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

Solution 1419352

Submitted on 18 Jan 2018 by David Verrelli
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|)')) )

ans = 1×1 cell array {1×5 double} ans = 1 2 3 4 5

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

ans = 1×3 cell array {1×3 double} {1×3 double} {1×3 double} ans = 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|)')) )

ans = 1×2 cell array {1×3 double} {1×3 double} ans = 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|)')) )

ans = 1×1000 cell array Columns 1 through 11 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 12 through 22 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 23 through 33 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 34 through 44 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 45 through 55 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 56 through 66 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 67 through 77 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 78 through 88 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 89 through 99 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 100 through 110 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 111 through 121 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 122 through 132 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 133 through 143 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 144 through 154 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 155 through 165 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 166 through 176 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 177 through 187 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 188 through 198 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 199 through 209 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 210 through 220 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 221 through 231 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 232 through 242 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 243 through 253 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 254 through 264 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 265 through 275 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 276 through 286 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 287 through 297 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 298 through 308 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 309 through 319 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 320 through 330 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 331 through 341 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 342 through 352 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 353 through 363 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 364 through 374 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 375 through 385 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 386 through 396 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 397 through 407 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 408 through 418 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 419 through 429 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 430 through 440 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 441 through 451 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 452 through 462 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 463 through 473 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 474 through 484 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 485 through 495 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 496 through 506 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 507 through 517 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 518 through 528 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} Columns 529 through 539 {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 double} {1×4 dou...