Cody

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

Solution 2782714

Submitted on 4 Aug 2020 by Ilia Belskii
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|)')) )

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

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

### Community Treasure Hunt

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

Start Hunting!