Cody

Problem 42691. Matrix of almost all zeros, except for main diagonal

Solution 2626927

Submitted on 29 Jun 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
x = 5; y_correct = [1 0 0 0 0; 0 2 0 0 0; 0 0 3 0 0; 0 0 0 4 0; 0 0 0 0 5] assert(isequal(mat(x),y_correct))

Error in solution: Line: 4 Column: 7 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

2   Fail
x = 10; y_correct = [1 0 0 0 0 0 0 0 0 0; 0 2 0 0 0 0 0 0 0 0; 0 0 3 0 0 0 0 0 0 0; 0 0 0 4 0 0 0 0 0 0; 0 0 0 0 5 0 0 0 0 0; 0 0 0 0 0 6 0 0 0 0; 0 0 0 0 0 0 7 0 0 0; 0 0 0 0 0 0 0 8 0 0; 0 0 0 0 0 0 0 0 9 0; 0 0 0 0 0 0 0 0 0 10] assert(isequal(mat(x),y_correct))

Error in solution: Line: 4 Column: 7 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

Suggested Problems

Community Treasure Hunt

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

Start Hunting!