MATLAB: How to find the element in on boundary or interior

a=[3 4 5;6 1 2]
I want to know if the element 2 is on boundary or interior?
how will i check?

Best Answer

tf = false(size(a))
tf(2:end-1,2:end-1) = true
a(tf) % elements in interior
a(~tf) % elements on boundary