It seems to be trivial code,if I understood properly.And I don't want to share any code but algorithm or logic to get your desired o/p.
1.Generate a random number between 1 and n;here n is nothing but [n,m]=size(i/p_matrix)
2.Declare a new empty matrix(as many times as you need) in a loop.
3.Start copying the elements row vise(how many number of rows you copy to the new empty matrix depends on the random number you have generated instantly).
Hope the above one works.