MATLAB: How to find the index of the center element in a 2d array if all the elements are the same

indexing

I'm attempting to find the index of the center element to be used later on.
I have a 5×5 array of -1's created with the following code.
x = -1*ones(5,5)
I'm able to find the index of the center element if the center element differs from the other elements using find (x == value).

Best Answer

If all the elements are the same, one approach is:
x = -1*ones(5,5);
[r,c] = ind2sub(size(x), ceil(numel(x)/2))
Thsi will only work on matrices with odd numbers of elements.