Cody

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

Solution 1405334

Submitted on 5 Jan 2018 by Noriko HOUNOKI
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
A = 1; IND = 1; b = 1; y_correct = [1;1]; assert(isequal(insertRows(A, IND, b), y_correct))

2   Pass
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))

b1 = 0 0 b2 = NaN NaN b3 = 1 1 NaN NaN A = 0 0 NaN NaN 1 1 NaN NaN b1 = 0 0 b2 = NaN NaN b3 = NaN NaN 1 1 NaN NaN A = 0 0 NaN NaN NaN NaN 1 1 NaN NaN b1 = 0 0 b2 = NaN NaN b3 = NaN NaN NaN NaN 1 1 NaN NaN A = 0 0 NaN NaN NaN NaN NaN NaN 1 1 NaN NaN

3   Pass
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))

b1 = 1 1 b2 = 2 2 b3 = 3 3 4 4 5 5 A = 1 1 2 2 3 3 4 4 5 5

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

b1 = 1 3 5 7 b2 = 8 b3 = 9 10 A = 1 3 5 7 8 9 10 b1 = 1 3 5 b2 = 6 b3 = 7 8 9 10 A = 1 3 5 6 7 8 9 10 b1 = 1 3 b2 = 4 b3 = 5 6 7 8 9 10 A = 1 3 4 5 6 7 8 9 10 b1 = 1 b2 = 2 b3 = 3 4 5 6 7 8 9 10 A = 1 2 3 4 5 6 7 8 9 10

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))

b1 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b2 = 0.2025 0.3947 0.3856 0.0893 0.1502 b3 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2025 0.3947 0.3856 0.0893 0.1502 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b1 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b2 = 0.5187 0.6080 0.3046 0.1418 0.2483 b3 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2025 0.3947 0.3856 0.0893 0.1502 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5187 0.6080 0.3046 0.1418 0.2483 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2025 0.3947 0.3856 0.0893 0.1502 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

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