MATLAB: How to make smaller matrices (size unknown) from a large matrix

large matrix

I have a matrix that has 51 columns and 46999 rows. The 8th column has values 1 to 36. I want to create a matrix for each value in that column (36 total). I want to stack rows that have the same value to make these matrices.
Thus far I know can use a for loop to set up a matrix 36 times then I was trying to use a while loop to "stack" the rows that share the same value in the 8th column, but I can't get that while loop right. Any suggestions?

Best Answer

M = your matrix;
result = cellfun(@(x)M(M(:,8)==x,:),num2cell(1:36),'uni',false);