produce combination one by one error
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I want to produce combination to check some condition. For finding combination, I used combnk.
but if
n = 32;
newn = 31;
indices = combnk(1:n, newn);
I got "out of memory" error. For solving this problem I used nextchoose to produce combination one by one.
H = nextchoose(n,newn);
for ii = 1:(prod(1:n)/(prod(1:(n-newn)) * prod(1:newn)))
indices_matrix = H();
%% do some calculation
end
But I got this error
Array indices must be positive integers or logical values.
Error in nextchoose/nestfunc (line 96)
lim = WV(K+1-inc); % lim for next run.
Is there any way to fix this?
0 Commenti
Risposte (1)
jmac
il 5 Giu 2020
For n=32 and newn=31, indices should be a 32x31 matrix; you should not get an "out of memory" error.
For different values of n end newn you may get introuble, since C(n,k) grows pretty fast. For example, for newn=16 you get over 600M combinations (you will need >150GB of memory to hold that matrix).
I tested nextchoose.m and worked pretty well. From your error message it seems that the limit testing on line 79 of nextchoose.m did not capture the end of the cycle, so you got to line 96 with k+1-inc negative.
I suspect you may be changing one or more of the persistent variables of the nested function during your calculation, somehow.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!