Implemented resize function for matrix layout