Find all possible combinations of string array
显示 更早的评论
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
采纳的回答
更多回答(1 个)
David Hill
2021-12-7
编辑:David Hill
2021-12-7
You could get all possible combinations and then index into your struct.
[idxa,idxb,idxc]=ndgrid(1:5,1:3,1:7);
类别
在 帮助中心 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!