Return the middle element of an NxN square matrix where N is odd - MATLAB Cody - MATLAB Central

Problem 56155. Return the middle element of an NxN square matrix where N is odd

Difficulty:Rate
Let's say you are given an NxN square matrix where N is always going to be an odd number:
x = [ 1 2 3
4 5 6
7 8 9 ]
Your function should return 5.
Edge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:
% Input Matrix
x = []
% Correct answer returned by your function
y = NaN

Solution Stats

43.1% Correct | 56.9% Incorrect
Last Solution submitted on Oct 15, 2024

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
12
4

Problem Recent Solvers24

Suggested Problems

More from this Author1

Community Treasure Hunt

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

Start Hunting!
Go to top of page