Nested For Loop Without Repetitions! PLEASE HELP
2 次查看(过去 30 天)
显示 更早的评论
My problem is that I have a array of strings, which are names, that can vary in length depending on how many the user inputs. I am okay up until that point, but I also want to store every combination of six of the names in the array. I was using six nested loops that ran from one to the number of names so that it would run through all combinations of the names. The issues are that with that method, the same name can show up multiple times in a collection of six name, the same combination of people can show up just in a different order, and it seems to take a long time.
I was trying to get rid of the same name showing up in the same grouping of six people with an if statement, but it seems tedious and also adds time. There are normally around 20 people inputted so that would be 64,000,000 different combinations if I did not filter out the repeated names and repeated groups. This just takes a lot of time because I am also trying to add if statements for specific characteristics of the people, which again adds more time.
Anyways, I would greatly appreciate if someone had a efficient way to run through every combination of picking six people from the group with no repeated names in each group and no repeated groups overall.
I have been trying to figure this out for a long time now and just can't wrap my mind around it, so if someone knows an answer please help! Thanks so much!
1 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!