Cody

# Problem 42697. sparse_matrix

Solution 1032324

Submitted on 26 Oct 2016 by Massimo Zanetti
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 = [ones(1,10) 2*ones(1,10)]; y_correct = [ones(1,10) zeros(1,10);zeros(1,10) ones(1,10)]; assert(isequal(sprs2matrix(x),y_correct));

ans = (1,1) 1 (1,2) 1 (1,3) 1 (1,4) 1 (1,5) 1 (1,6) 1 (1,7) 1 (1,8) 1 (1,9) 1 (1,10) 1 (2,11) 1 (2,12) 1 (2,13) 1 (2,14) 1 (2,15) 1 (2,16) 1 (2,17) 1 (2,18) 1 (2,19) 1 (2,20) 1

2   Pass
x = 1:100; y_correct = eye(100); assert(isequal(sprs2matrix(x),y_correct));

ans = (1,1) 1 (2,2) 1 (3,3) 1 (4,4) 1 (5,5) 1 (6,6) 1 (7,7) 1 (8,8) 1 (9,9) 1 (10,10) 1 (11,11) 1 (12,12) 1 (13,13) 1 (14,14) 1 (15,15) 1 (16,16) 1 (17,17) 1 (18,18) 1 (19,19) 1 (20,20) 1 (21,21) 1 (22,22) 1 (23,23) 1 (24,24) 1 (25,25) 1 (26,26) 1 (27,27) 1 (28,28) 1 (29,29) 1 (30,30) 1 (31,31) 1 (32,32) 1 (33,33) 1 (34,34) 1 (35,35) 1 (36,36) 1 (37,37) 1 (38,38) 1 (39,39) 1 (40,40) 1 (41,41) 1 (42,42) 1 (43,43) 1 (44,44) 1 (45,45) 1 (46,46) 1 (47,47) 1 (48,48) 1 (49,49) 1 (50,50) 1 (51,51) 1 (52,52) 1 (53,53) 1 (54,54) 1 (55,55) 1 (56,56) 1 (57,57) 1 (58,58) 1 (59,59) 1 (60,60) 1 (61,61) 1 (62,62) 1 (63,63) 1 (64,64) 1 (65,65) 1 (66,66) 1 (67,67) 1 (68,68) 1 (69,69) 1 (70,70) 1 (71,71) 1 (72,72) 1 (73,73) 1 (74,74) 1 (75,75) 1 (76,76) 1 (77,77) 1 (78,78) 1 (79,79) 1 (80,80) 1 (81,81) 1 (82,82) 1 (83,83) 1 (84,84) 1 (85,85) 1 (86,86) 1 (87,87) 1 (88,88) 1 (89,89) 1 (90,90) 1 (91,91) 1 (92,92) 1 (93,93) 1 (94,94) 1 (95,95) 1 (96,96) 1 (97,97) 1 (98,98) 1 (99,99) 1 (100,100) 1

3   Pass
x = [1 4 5 3 6]; y_correct = [1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1]; assert(isequal(sprs2matrix(x),y_correct));

ans = (1,1) 1 (4,2) 1 (5,3) 1 (3,4) 1 (6,5) 1

4   Pass
x = 10; y_correct = zeros(x,1); y_correct (x)=1; assert(isequal(sprs2matrix(x),y_correct));

ans = (10,1) 1

### Community Treasure Hunt

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

Start Hunting!