Cody

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

Solution 287238

Submitted on 22 Jul 2013 by Evan
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 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 = 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 = 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 = Columns 1 through 8 1 2 3 4 6 7 8 9 Columns 9 through 16 11 12 13 14 16 17 18 19 Columns 17 through 24 21 22 23 24 26 27 28 29 Columns 25 through 32 31 32 33 34 36 37 38 39 Columns 33 through 40 41 42 43 44 46 47 48 49 Columns 41 through 48 51 52 53 54 56 57 58 59 Columns 49 through 56 61 62 63 64 66 67 68 69 Columns 57 through 64 71 72 73 74 76 77 78 79 Columns 65 through 72 81 82 83 84 86 87 88 89 Columns 73 through 80 91 92 93 94 96 97 98 99 Columns 81 through 88 101 102 103 104 106 107 108 109 Columns 89 through 96 111 112 113 114 116 117 118 119 Columns 97 through 104 121 122 123 124 126 127 128 129 Columns 105 through 112 131 132 133 134 136 137 138 139 Columns 113 through 120 141 142 143 144 146 147 148 149 Columns 121 through 128 151 152 153 154 156 157 158 159 Columns 129 through 136 161 162 163 164 166 167 168 169 Columns 137 through 144 171 172 173 174 176 177 178 179 Columns 145 through 152 181 182 183 184 186 187 188 189 Columns 153 through 160 191 192 193 194 196 197 198 199 Columns 161 through 168 201 202 203 204 206 207 208 209 Columns 169 through 176 211 212 213 214 216 217 218 219 Columns 177 through 184 221 222 223 224 226 227 228 229 Columns 185 through 192 231 232 233 234 236 237 238 239 Columns 193 through 200 241 242 243 244 246 247 248 249 Columns 201 through 208 251 252 253 254 256 257 258 259 Columns 209 through 216 261 262 263 264 266 267 268 269 Columns 217 through 224 271 272 273 274 276 277 278 279 Columns 225 through 232 281 282 283 284 286 287 288 289 Columns 233 through 240 291 292 293 294 296 297 298 299 Columns 241 through 248 301 302 303 304 306 307 308 309 Columns 249 through 256 311 312 313 314 316 317 318 319 Columns 257 through 264 321 322 323 324 326 327 328 329 Columns 265 through 272 331 332 333 334 336 337 338 339 Columns 273 through 280 341 342 343 344 346 347 348 349 Columns 281 through 288 351 352 353 354 356 357 358 359 Columns 289 through 296 361 362 363 364 366 367 368 369 Columns 297 through 304 371 372 373 374 376 377 378 379 Columns 305 through 312 381 382 383 384 386 387 388 389 Columns 313 through 320 391 392 393 394 396 397 398 399 Columns 321 through 328 401 402 403 404 406 407 408 409 Columns 329 through 336 411 412 413 414 416 417 418 419 Columns 337 through 344 421 422 423 424 426 427 428 429 Columns 345 through 352 431 432 433 434 436 437 438 439 Columns 353 through 360 441 442 443 444 446 447 448 449 Columns 361 through 368 451 452 453 454 456 457 458 459 Columns 369 through 376 461 462 463 464 466 467 468 469 Columns 377 through 384 471 472 473 474 476 477 478 479 Columns 385 through 392 481 482 483 484 486 487 488 489 Columns 393 through 400 491 492 493 494 496 497 498 499 Columns 401 through 408 501 502 503 504 506 507 508 509 Columns 409 through 416 511 512 513 514 516 517 518 519 Columns 417 through 424 521 522 523 524 526 527 528 529 Columns 425 through 432 531 532 533 534 536 537 538 539 Columns 433 through 440 541 542 543 544 546 547 548 549 Columns 441 through 448 551 552 553 554 556 557 558 559 Columns 449 through 456 561 562 563 564 566 567 568 569 Columns 457 through 464 571 572 573 574 576 577 578 579 Columns 465 through 472 581 582 583 584 586 587 588 589 Columns 473 through 480 591 592 593 594 596 597 598 599 Columns 481 through 488 601 602 603 604 606 607 608 609 Columns 489 through 496 611 612 613 614 616 617 618 619 Columns 497 through 504 621 622 623 624 626 627 628 629 Columns 505 through 512 631 632 633 634 636 637 638 639 Columns 513 through 520 641 642 643 644 646 647 648 649 Columns 521 through 528 651 652 653 654 656 657 658 659 Columns 529 through 536 661 662 663 664 666 667 668 669 Columns 537 through 544 671 672 673 674 676 677 678 679 Columns 545 through 552 681 682 683 684 686 687 688 689 Columns 553 through 560 691 692 693 694 696 697 698 699 Columns 561 through 568 701 702 703 704 706 707 708 709 Columns 569 through 576 711 712 713 714 716 717 718 719 Columns 577 through 584 721 722 723 724 726 727 728 729 Columns 585 through 592 731 732 733 734 736 737 738 739 Columns 593 through 600 741 742 743 744 746 747 748 749 Columns 601 through 608 751 752 753 754 756 757 758 759 Columns 609 through 616 761 762 763 764 766 767 768 769 Columns 617 through 624 771 772 773 774 776 777 778 779 Columns 625 through 632 781 782 783 784 786 787 788 789 Columns 633 through 640 791 792 793 794 796 797 798 799 Columns 641 through 648 801 802 803 804 806 807 808 809 Columns 649 through 656 811 812 ...

### Community Treasure Hunt

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

Start Hunting!