Unit Matrix - MATLAB Cody - MATLAB Central

Problem 1926. Unit Matrix

Difficulty:Rate
Given n, you should return an n-by-n unit matrix.
Example:
If input is n=2 then
A = [ 1 0
0 1 ]
If input is n=4 then
A = [ 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1 ]

Solution Stats

79.33% Correct | 20.67% Incorrect
Last Solution submitted on Oct 27, 2025

Problem Comments

Solution Comments

Show comments
Join Cody Contest 2025 — Have Fun and Win Prizes!
...
We’re excited to invite you to Cody Contest 2025! 🎉 Pick a team,...

Problem Recent Solvers500

Suggested Problems

Community Treasure Hunt

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

Start Hunting!