MATLAB: I need to degenerate a matrix. I have 1 column with 11,2,2,2,3​,3..748,74​9,749 ( max 5 repetitions for each integer, but random, 2340 in total), I need to select the data in the rows with the same integer value and pick one at random to give 749 r

i need to degenerate a matrix. I have 1 column with 1,1,2,2,2,3,3..748,749,749 ( max 5 repetitions for each integer, but random, 2340 in total), I need to select the data in the rows with the same integer value and pick one at random to give 749 rows

Best Answer

out=cell2mat(accumarray(A(:,1),(1:numel(A(:,1)))',[],@(x) {A(x(randi(numel(x))),:)}))