MATLAB: I need help finding the center of an n * n array. TA couldn’t figure it out

centern * nta

Assign middleElement with the element in the center of squareArray. Assume squareArray is always an n x n array, where n is odd. Hint: elementIndex should be rounded to an integer. Ex: If squareArray is [1, 2, 3; 4, 5, 6; 7, 8, 9], then middleElement is 5.
function middleElement = FindMiddle(squareArray)
% FindMiddle: Return the element in the center of squareArray
% Inputs: squareArray - n x n input array, where n is odd
%
% Outputs: selectedData - center element of squareArray
% Assign elementIndex with location of middle row/col
% Hint: Use the size() function to deterimine the dimension of squareArray
elementIndex = size(squareArray); %3.5 /2
% Assign middleElement with the center element of squareArray
middleElement = squareArray(elementIndex);
end

Best Answer

Like this:
m = [1, 2, 3; 4, 5, 6; 7, 8, 9]
middleElement = m(ceil(numel(m)/2))