Generate a large power set in batches?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Peta
am 17 Feb. 2016
Kommentiert: Peta
am 18 Feb. 2016
Say I want to generate the power set of a number and store as logical combinations using this formula for example:
idx = dec2bin(0:2^n-1,n)=='1';
But the n value I want to use is big enough that the resulting idx variable becomes too large to store in memory or work with. Is there any way that I can generate the power set batch-wise in a loop so I only have to store parts of it at a time but in the end I will have worked my way though all of it?
So for example, is there any way I can generate the first 100 values of the set and then start regenerating at 101 and go to 200 etc?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Feb. 2016
Bearbeitet: Walter Roberson
am 18 Feb. 2016
n = 14; %for example
batch_size = 100;
maxidx = 2^n - 1;
for k = 0 : ceil(maxidx/batch_size)
high = min(maxidx, (k+1)*batch_size - 1);
idx = dec2bin(k * batch_size : high, n) == '1';
...
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Licensing on Cloud Platforms finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!