Cody

Problem 2009. Insert certain elements into a vector.

Solution 3453023

Submitted on 28 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
v = 1:5; u = [2 4]; w = [0 -1]; y = insert_some(v,w,u); y_correct = [1 0 2 3 -1 4 5]; assert(isequal(y,y_correct)) filetext = fileread('insert_some.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp* command is forbidden'); assert(isempty(strfind(filetext, 'eval')),'eval* command is forbidden'); assert(isempty(strfind(filetext, 'inline')),'inline command is forbidden');

Assertion failed.

2   Fail
v = 1:100; u = 1:100; w = 1:100; y = insert_some(v,w,u); y_correct = reshape(repmat(1:100,2,1),1,[]); assert(isequal(y,y_correct))

Matrix index is out of range for deletion. Error in insert_some (line 5) y(cumsum(u))=[]; Error in Test2 (line 4) y = insert_some(v,w,u);

3   Fail
v = 0:99; u = 11:10:101; w = repmat(nan,1,10); y = insert_some(v,w,u); y_correct = reshape([reshape(v,10,[]);repmat(nan,1,10)],1,[]); assert(isequaln(y,y_correct))

Matrix index is out of range for deletion. Error in insert_some (line 5) y(cumsum(u))=[]; Error in Test3 (line 4) y = insert_some(v,w,u);

4   Fail
v = repmat(1:2,1,100); w = repmat(3,1,100); u = 3:2:201; y = insert_some(v,w,u); y_correct = repmat(1:3,1,100); assert(isequaln(y,y_correct))

Matrix index is out of range for deletion. Error in insert_some (line 5) y(cumsum(u))=[]; Error in Test4 (line 4) y = insert_some(v,w,u);

Community Treasure Hunt

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

Start Hunting!