Is there a command or one-line strategy in MATLAB that will return all the combinations of the components of n
cell arrays, taken n
at a time?
An example of what I want to accomplish:
A = {'a1','a2'};
B = {'b1','b2','b3'};
C = combinations(A,B)
C = {'a1','b1' ;
'a1','b2' ;
'a1','b3' ;
'a2','b1' ;
'a2','b2' ;
... }
The command would be able to accept an arbitrary number of arguments and the result in the example would have as many columns as there are arguments to the function. (Of course, the syntax above is just meant for illustration and any method that would generate the results whatever the format would fit the bill)
EDIT: Similar questions have been asked for matrices instead of cells, e.g. link. Many solutions point to the FEX submission allcomb, but all such solutions are just wrappers around ndgrid, which only work with doubles. Any suggestions for non numeric sets?