Cody

Problem 1958. Add a row of zeros on top of a matrix

Solution 675154

Submitted on 26 May 2015 by Gareth Lee
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
%% x = rand(4); y_correct = [zeros(1,size(x,2));x]; assert(isequal(addrow(x),y_correct))

ans = 0 0 0 0 0.3455 0.6976 0.7945 0.1575 0.6771 0.1821 0.0929 0.8094 0.8756 0.6968 0.6925 0.9242 0.7355 0.4609 0.8708 0.2148

2   Pass
%% x = []; y_correct = zeros(1,0); assert(isequal(addrow(x),y_correct))

ans = Empty matrix: 1-by-0

3   Pass
%% x = rand(8,1); y_correct = [zeros(1,size(x,2));x]; assert(isequal(addrow(x),y_correct))

ans = 0 0.1429 0.9816 0.8470 0.6904 0.5747 0.0489 0.9840 0.8028

4   Pass
%% x = zeros(0,1); y_correct = 0; assert(isequal(addrow(x),y_correct))

ans = 0

Suggested Problems

More from this Author31

Community Treasure Hunt

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

Start Hunting!