Cody

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

Solution 3150526

Submitted on 10 Oct 2020
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   Fail
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|)')) )

Output argument "y" (and maybe others) not assigned during call to "interleaved_idx>do_it_by_recursion". Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx (line 2) ans = do_it_by_recursion([],x1,x2); Error in Test1 (line 3) assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

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

Output argument "y" (and maybe others) not assigned during call to "interleaved_idx>do_it_by_recursion". Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx (line 2) ans = do_it_by_recursion([],x1,x2); Error in Test2 (line 3) assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

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

Output argument "y" (and maybe others) not assigned during call to "interleaved_idx>do_it_by_recursion". Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))]; Error in interleaved_idx (line 2) ans = do_it_by_recursion([],x1,x2); Error in Test3 (line 3) assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

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

Output argument "y" (and maybe others) not assigned during call to "interleaved_idx>do_it_by_recursion". Error in interleaved_idx>do_it_by_recursion (line 8) [x1(1):x2(1), do_it_by_recursion(ans,x1(2:end),x2(2:end))];

Suggested Problems

More from this Author3

Community Treasure Hunt

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

Start Hunting!