Problem 43689. Make an identity matrix whose diagonal elements are 1:n
For a given input n, make an n by n identity matrix that contains the elements 1:n along its diagonal. For example, if input=5:
output = [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]
Solution Stats
Problem Comments
-
1 Comment
goc3
on 21 Dec 2016
This problem's title and description were cleaned up and additional test cases were added.
Solution Comments
Show commentsProblem Recent Solvers121
Suggested Problems
-
Which values occur exactly three times?
5232 Solvers
-
Replace NaNs with the number that appears to its left in the row.
3059 Solvers
-
All your base are belong to us
571 Solvers
-
Calculate the area of a triangle between three points
3402 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
13513 Solvers
More from this Author7
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!