Find all possible combinations of string array
Show older comments
Hi,
i have a struct that contains cells of different dimensions. I need a way to find all possible combinations of all cells.
The cells containing string variable e.g: matrix(1).elements = {'500A', '600B', '700C',''}, matrix(2).elements = {'100AC', '300D', '200CA','60G'}, matrix(3).elements = {'100BC', '300DF', '200AA','60GR'}...(some cells have less variables and for this reason i have " at the last element of matrix(1))
The total number of combinations in the example above is: 4*4*4=64
The results that i would like is a mat like: 1) 500A,100AC, 100BC,
2) 500A,100AC, 300DF
3) 500A,100AC, 200AA...
I tried allcomb function but it doesn't work
Any idea on that?
Thanks in advance
Accepted Answer
More Answers (1)
David Hill
on 7 Dec 2021
Edited: David Hill
on 7 Dec 2021
You could get all possible combinations and then index into your struct.
[idxa,idxb,idxc]=ndgrid(1:5,1:3,1:7);
1 Comment
Christos Traianos
on 9 Dec 2021
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!