If your two matrices are same size, simple, just x = M - N; If they are not, you can still x = M(ind) - N(ind) where ind is a one-dimension array. Then x will end up as a vector. No matter how many dimension a matrix is, it always saves as 1D vector in memory. So you can always manipulate it as 1D vector.