MATLAB Answers

get a combination of unique paths for given pair of numbers

17 views (last 30 days)
ONKAR BHANDARE
ONKAR BHANDARE on 23 Oct 2020
Commented: ONKAR BHANDARE on 23 Oct 2020
I need to get combination of all unique paths. I have a path as follows:
107 111 354 371 326 375 145
pipe# 107 has 2 other pipes - 108 and 109
similarly, 354 has another 355
375 has 378 and 382
Desired output from [107/108/109], 111, [354 355], 371, 326, [375 378 382], 145 should be :
107 111 354 371 326 375 145
108 111 354 371 326 375 145
109 111 354 371 326 375 145
107 111 355 371 326 375 145
108 111 355 371 326 375 145
109 111 355 371 326 375 145
107 111 354 371 326 378 145
108 111 354 371 326 378 145
109 111 354 371 326 378 145
107 111 355 371 326 378 145
108 111 355 371 326 378 145
109 111 355 371 326 378 145
107 111 354 371 326 382 145
108 111 354 371 326 382 145
109 111 354 371 326 382 145
107 111 355 371 326 382 145
108 111 355 371 326 382 145
109 111 355 371 326 382 145
I would really appreciate if you could help me with the code or an idea. Thank you!!

Answers (1)

Walter Roberson
Walter Roberson on 23 Oct 2020
This is easy to calculate using a code pattern that I call "odometer". Each cycle, move on to next valid entry in the last position, and when it reaches the maximum, "roll over" it and increment the second last... rolling it over as necessary. The general code pattern does not require that each position has the same number of possibilities.
https://www.mathworks.com/matlabcentral/answers/602395-different-number-of-for-loops#answer_502861
  3 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!