I'm trying to sort through a very large matrix (12×4^12). It's actually a matrix generated by combinator of all possible permutations with repetitions of choosing 12 from 4 , though that's not critical to this question. What I need to do is identify all columns in which each number is repeated no more than x times (say x = 3 here). Here's simplified sample code:
x = 3;poss = randi(4,12,4^12); % in my code: poss = combinator(4,12,'p','r')';
[M,F] = mode(poss,1);evenposs = poss(:, F<=x );
My problem is that the third line above (with mode) is very slow, over 400 seconds on my computer, so it seems that doing it through the mode function is highly inefficient. Obviously I could do this with a for loop, but I've been trained to avoid that in Matlab – I thought this mode function might have been a crafty way to avoid the loop, but now I'm wondering if there are still craftier ways of achieving this.
Bonus points (i.e. my eternal gratitude) if anybody can suggest a way of using combinator or another package to generate permutations with limited repetitions, so that I can avoid this filtering step entirely.
Best Answer