Combinations of variables and step sizing for creation of DOE

7 ビュー (過去 30 日間)
Paul
Paul 2012 年 1 月 25 日
I'm using matlab to create .txt files containing variables for another program.
I'm trying to create a Design Of Experiments.
An example is, I have 3 variables,v1=5,v2=15 and v3=100
Now each variable also has a step size, v1s=1, v2s=5, v3s=10
and each variable steps by different amounts, so v1a=3,v2a=4,v3a=5
So now I have 3*4*5=60 possible different combinations.
so combination no: 1= 5,15,100 2= 6,15,100 3= 7,15,100 4= 5,20,100 5= 5,25,100 etc....
I'm trying to think of a way that can create all this on the fly for any amount of variables and step sizes but really coming unstuck here.
If anyone has some help it would be greatly appreciated.
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2012 年 1 月 25 日
I do not understand about "steps by different amounts" as distinct from "step size" ?
It is not clear from what you posted that there are upper bounds on your variables.
If there are upper bounds on the variables, then for each variable construct the list of valid values and toss it in to a cell array entry, such as
varvals{4} = v1 : v1s : v1end;
When you have them all constructed, then
[valgrids{1:length(varvals)}] = ndgrid(varvals{:});
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 25 日
Once you have done the above two steps,
tt = cellfun(@(M) reshape(M,[],1), valgrids,'Uniform',0);
combos = horzcat(tt{:}) .';

サインインしてコメントする。

その他の回答 (2 件)

Tom Lane
Tom Lane 2012 年 1 月 25 日
Do you have the Statistics Toolbox available? It seems like what you want is a full factorial design, but with the variable levels chosen from a set other than {1,2,...,k}. Here's an example creating a two-variable design with every combination of {10,20} for the first variable and {100,200,300} for the second.
>> s1 = [10 20];
>> s2 = [100 200 300];
>> x = fullfact([2 3])
x =
1 1
2 1
1 2
2 2
1 3
2 3
>> x(:,1) = s1(x(:,1));
>> x(:,2) = s2(x(:,2))
x =
10 100
20 100
10 200
20 200
10 300
20 300
This is similar to Walter's ndgrid idea, but for three variables it gives a three-column matrix instead of three separate MATLAB variables.
  1 件のコメント
Noubara Djimadoumbaye
Noubara Djimadoumbaye 2012 年 2 月 2 日
Thanks Tom Lane. This answers to my question. Good night!

サインインしてコメントする。


Paul
Paul 2012 年 1 月 25 日
Let me try and rephrase this again, after reading my first question I don't believe I got my point across very well.
Yes for my variables I will have the lower limit and upper limit so the
varvals{4} = v1 : v1s : v1end;
works perfectly to give the range.
But I still have the problem.
Lets say I have
varvals{1} = 100 : 20 : 200
varvals{2} = 5 : 2 : 11
varvals{3} = 50 : 10 : 70
varvals{4} = 5 : 2 : 11
length(varvals{1})
length(varvals{2})
length(varvals{3})
length(varvals{4})
ans =
6
ans =
4
ans =
3
ans =
4
and now 6*4*3*4=288
Which means out of the 4 variables I can make 288 different combinations.
What my program needs to do is store all these 288 combinations into different files, eg output_1.txt output_2.txt..... output_288.txt
The file writing part is easying, sorting the data into a matrix is now what I'm having trouble with.
In this situation I would need a matrix of size (4,288) so each column is one of the unique 288 combinations, then I can just write each column into my separate file.
Creating this matrix is what I'm now stuck on.
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 25 日
I added the final two steps to my Answer above.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by