A=[randi(9,100,4) randi([1 4],100,1)] % Example
[ii,jj,kk]=unique(A(:,5))
m=accumarray(kk,(1:numel(kk))',[],@(x) {x'})
out=cell2mat(cellfun(@(x) A(x(randperm(numel(x),2)),:),m,'un',0))
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!