is there any way to set up a script to run a general amount of nested loops?

1 visualización (últimos 30 días)
for example if i have a 3d array is there anyway to automatically loop through all pages and select 1 row from each page to create a new 2d array for each iteration, without having to manually specify how many nested loops i need? The number of pages of my 3d array changes throughout my project so would be handy to not have to specify
example of my array : val(:,:,1) =
1 7
2 8
3 9
4 10
6 2
7 3
8 4
9 5
val(:,:,2) =
6 12
7 13
8 14
9 15
11 7
12 8
13 9
14 10
val(:,:,3) =
11 17
12 18
13 19
14 20
16 12
17 13
18 14
19 15
val(:,:,4) =
16 22
17 23
18 24
19 25
21 17
22 18
23 19
24 20
val(:,:,5) =
21 27
22 28
23 29
24 30
26 22
27 23
28 24
29 25
val(:,:,6) =
26 32
27 33
28 34
29 35
31 27
32 28
33 29
34 30

Respuestas (1)

Ahmet Cecen
Ahmet Cecen el 16 de Mzo. de 2018
Why not just do val(1,:,:) or val(i,:,:)?
  3 comentarios
Ahmet Cecen
Ahmet Cecen el 16 de Mzo. de 2018
Ah. This maybe intractable for large number of "pages" but you can always do something like:
CombList = combnk(1:size(Val,1),size(Val,3));
Which will you give you every row combination possible.
Now you can do a single loop to go through all iterations independent of the number of rows or pages.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by