Updated with code

both functions were tested with  matrix(1:4,2,2) example