For a positive integer n create the identity matrix with n elements.

In case it is not possible to produce an identity matrix with exactly n elements, return an empty matrix.

Examples:

Input:  n = 9
Output: I = [1 0 0
             0 1 0
             0 0 1]
Input:  n = 8
Output: I = []

Solution Stats

1191 Solutions

235 Solvers

Last Solution submitted on May 29, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers235

Suggested Problems

More from this Author25

Problem Tags

Community Treasure Hunt

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

Start Hunting!