Draw a X - MATLAB Cody - MATLAB Central

Problem 54840. Draw a X

Difficulty:Rate
Given an input n , create a square matrix of zeros with an X of ones.
Ex.
n = 3
drawX(3)
[ 1 0 1
0 1 0
1 0 1 ]
Ex.
n = 7
drawX(7)
[ 1 0 0 0 0 0 1
0 1 0 0 0 1 0
0 0 1 0 1 0 0
0 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 0 0 0 1 0
1 0 0 0 0 0 1 ]

Solution Stats

85.37% Correct | 14.63% Incorrect
Last Solution submitted on Feb 10, 2025

Solution Comments

Show comments
Registration Now Open for MathWorks AUTOMOTIVE CONFERENCE 2025
...
Hello Community, We're excited to announce that registration is now open for the...

Problem Recent Solvers33

Suggested Problems

Community Treasure Hunt

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

Start Hunting!
Go to top of page