Cody

# Problem 796. Removing rows from a matrix is easy - but what about inserting rows?

Solution 3034564

Submitted on 2 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
A = 1; IND = 1; b = 1; y_correct = [1;1]; assert(isequal(insertRows(A, IND, b), y_correct))

Assertion failed.

2   Fail
A = [0 0; 1 1]; IND = [1 1 1 2]; b = NaN; y_correct = [0 0;NaN NaN;NaN NaN;NaN NaN;1 1;NaN NaN]; assert(isequalwithequalnans(insertRows(A, IND, b), y_correct))

Index in position 2 exceeds array bounds (must not exceed 1). Error in insertRows (line 11) k(i+IND(i),j)=b(i,j); Error in Test2 (line 5) assert(isequalwithequalnans(insertRows(A, IND, b), y_correct))

3   Fail
A = [1 1; 3 3; 4 4]; IND = [1 3]; b = [2 2; 5 5]; y_correct = [1 1;2 2;3 3;4 4;5 5]; assert(isequal(insertRows(A, IND, b), y_correct))

m = 1 m = 2 m = 3 m = 4

Assertion failed.

4   Fail
A = (1:2:10)'; IND = 1:5; b = (2:2:10)'; y_correct = (1:10)'; assert(isequal(insertRows(A, IND, b), y_correct))

m = 1 m = 2

Assertion failed.

5   Pass
A = zeros(10,5); IND = [3,7]; b = rand(2,5); y_correct = [zeros(3,5); b(1,:); zeros(4,5); b(2,:); zeros(3,5)]; assert(isequal(insertRows(A, IND, b), y_correct))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16 m = 17 m = 18 m = 19 m = 20 m = 21 m = 22 m = 23 m = 24 m = 25 m = 26 m = 27 m = 28 m = 29 m = 30 m = 31 m = 32 m = 33 m = 34 m = 35 m = 36 m = 37 m = 38 m = 39 m = 40

6   Pass
assert(isempty(strfind(evalc('type insertRows'), 'regexp')));

### Community Treasure Hunt

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

Start Hunting!