I want to ask how to check all the combinations possibilities of P elements in a array with total N elements in Matlab? I am now trying to use P element from an array which contains N elements, let's say array A, to test in another program. If this group of P elements fails in the program, I will go back to array A and try another group of P elements. So each time the program will only test one group of P. if the program processed the P elements successfully, it program will stop and return TURE, otherwise it continue testing till all the cases are tested.
My current solution is that: I always take the first P elements in array A each iteration. If this time fails, then I start to shift the array from the Pth element to the end(Nth element). So next time the there will be a different element in the first P elements of A. It will continue shifting until (N-P) times try. then I start to shift from the (P-1)th element to the end once, and do the same shift method from the Pth to the end to test all the different cases with 2 different elements in the first P element.
If all the cases are tested to change the last two elements of the P elements, then test the last three elements....until it finds a group of P element which can be processed by the program or all the possible combinations are tested( return false).
My solution is done with a switch function for different number of P. And the code is increasing with the P increasing.
I want to ask if you guys have a better way to test all the possible combinations of a array in matlab? Also if there is a better way to do the iteration without do a switch in matlab?
I thought about using "perms", but this function is limited with at most 10 elements.
Thank you in advance!