AllCombIter

Version 1.0.0 (1.98 KB) by 一平 左
A iterative version of function allcomb, which compute all of the combinations of the elements of numbers of arrays.
17 Downloads
Updated 22 Mar 2021

View License

An iterative approach to compute all the combinations amnong undetermined number of 1D arrays.
Mr. Jos (https://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb-varargin) supplied a function `allcomb` which compute combinations of several arrays.
While the `allcomb` function return all of the combinations in a matrix form at once, it may crash when the number of combinations reachs a high level (i.e. run out of memeory).
A iterative version of `allcomb` is design to be a iterator-like object, it only return one combination when the method `next()` is called.
Notice that, it only compute the comb of 1D arrays!
Technically, it use a recursive approach in place of an undetermined nested of for-loop
Example:
A_range = 0:2:6;
B_range = 0:2:4;
C_range = 1:2;
iter = AllCombIter(A_range, B_range, C_range);
cmb = [];
while iter.hasNext()
comb = iter.next();
cmb = [cmb; comb];
end

Cite As

一平 左 (2024). AllCombIter (https://www.mathworks.com/matlabcentral/fileexchange/89117-allcombiter), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0