Help creating variable list listing all combinations for DOE

7 views (last 30 days)
Problem: An application (not MATLAB) reads in a text file which is a list of variables it will calculate. Each variable requires somewhere between 1 and 5 inputs. I need to create an exhaustive list of every combination of input variables for a design of experiments. The end result is a list with millions of lines showing each variable with every possible combination of inputs written to a text file.
Example: See the attached image showing the list of variables. CAPS specify the variable name and italics specify required inputs (separated by spaces).
For the sake of brevity, lets look at only the first 3 variables:
CUBIC PER ATR _HistLength_ ATRlength_
RSI _HistLength_
STOCHASTIC K _HistLength_
The inputs are HistLength and ATRlength which can take on the following values:
_HistLength_ = [10 50 100]
_ATRlength_ = [5 15 25]
The resulting text file would be (order of list is not important):
CUBIC PER ATR 10 5
CUBIC PER ATR 50 5
CUBIC PER ATR 100 5
CUBIC PER ATR 10 15
CUBIC PER ATR 50 15
CUBIC PER ATR 100 15
CUBIC PER ATR 10 25
CUBIC PER ATR 50 25
CUBIC PER ATR 100 25
RSI 10
RSI 50
RSI 100
STOCHASTIC K 10
STOCHASTIC K 50
STOCHASTIC K 100
Now try that for 100 variables with 1 to 5 inputs each and the list gets prohibitively long to type by hand!
What I've Tried: My previous attempts use strfind() in a loop to determine whether an input is present (such as HistLength) and, if true, use strrep() to replace the input string (HistLength) with the numerical values. Once multiple inputs are involved things get messy.
I am happy to provide examples of what I've tried but so none of them worked as they should. Mainly looking for suggestions as to how to approach the problem in an efficient manner.

Accepted Answer

dpb
dpb on 9 Sep 2016
Think you'll have to build some corollary data...
>> vars={'CUBIC PER ATR';'RSI';'STOCHASTIC K'}; % the list of variables
>> inps={[10 50 100];[5 15 25]}; % list of input values for each input variable
>> inVar={[1 2];[1];[1]}; % which inputs are used for each variable
The idea to generate the list for each variable is then pretty simple, albeit the output is, as you say, going to be quite large...
The number of combinations for each variable is the product of the size of the inputs list for the number of inputs for the variable; in the first case there are two inputs, each of length 3 so there are 3x3=9 combinations one-at-a-time. Matlab doesn't have a builtin function to do the combinations of N elements from M populations (that I can think of anyway) so just loop...for the first variable it's simply with the above definitions--
>> k=0; % loop counter
vv=zeros(9,2); % the size; use length() in earnest
for i=1:3
for j=1:3
k=k+1;
vv(k,:)=[inps{1}(i) inps{2}(j)];
end
end
>> vv
vv =
10 5
10 15
10 25
50 5
50 15
50 25
100 5
100 15
100 25
>>
For actual implementation, you'll enclose the above in a loop over the variables and need to make the indices of the loops dependent upon the length of the inps arrays for the given variable. It may be handier to use a cell of cells in order to be able to run loop with another index variable for the number possible inputs; I showed two identically here instead of a generic number that could be, as you say, from one to as many as five;

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!