in MATLAB handy function call reshape reshape m x n matrix new different size r x c keep original datayou give m x n matrix mat integer r c represent number row number column want reshape matrixthe reshaped matrix fill element original matrix rowtraverse order wereif reshape operation give parameter possible legal output new reshaped matrix Otherwise output original matrix Example 1input mat 1234 r 1 c 4output 1234example 2input mat 1234 r 2 c 4output 1234 Constraintsm matlengthn matilength1 m n 1001000 matij 10001 r c 300