Replace secondary diagonal elements of a square array - MATLAB Cody - MATLAB Central

Problem 42695. Replace secondary diagonal elements of a square array

Difficulty:Rate

Replace all the secondary diagonal elements of the square array A with the number n

Example:

 A = [1 2 3
      4 5 6
      7 8 9]
 n=0
 Output = [1 2 0
           4 0 6
           0 8 9]

Example 2

 A = 1;
 n = 10;
 Output = 10

Solution Stats

49.41% Correct | 50.59% Incorrect
Last Solution submitted on Oct 15, 2025

Problem Comments

Solution Comments

Show comments
AI Is Transforming Engineering Workflows
It’s an honor to deliver the keynote at MATLAB EXPO 2025. I'll...
0
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0

Problem Recent Solvers169

Suggested Problems

Community Treasure Hunt

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

Start Hunting!