D for loops concatenated
Mostra commenti meno recenti
I would like to generalize the following codes for dimension D=2:
D=2;
dim=factorial(P-1+D)/(factorial(P-1)*factorial(D));
indexes=zeros(dim,D);
s=0;
for i=1:P
for j=1:i
s=s+1;
indexes(s,:)=[i-j,j-1];
end
end
dimension D=3:
D=3;
dim=factorial(P-1+D)/(factorial(P-1)*factorial(D));
indexes=zeros(dim,D);
s=1;
for i=1:P
for j=1:i
for k=1:j
indexes(s,:)=[i-j,j-k,k-1];
s=s+1;
end
end
end
P can be an arbitrary integer (e.g. P=4).
In other words I would like to create D for loops in such a way that the first loop goes from 1 to P (i=1:P) the second loop from 1 to the previous one (j=1:i) the third one from 1 to the second one (h=1:j) etc.
Thank you in advance.
Risposta accettata
Più risposte (1)
Luca Fenzi
il 20 Ott 2015
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!