All possible Combinations and equation analysis

2 ビュー (過去 30 日間)
Nik Sam
Nik Sam 2016 年 5 月 17 日
コメント済み: Nik Sam 2016 年 5 月 17 日
Hello everyone,
1) How can I get all possible combinations?
for example: a=[1 2] , b=[2 3] , c=[1 4] and I want this as a result
d1=1 2 1
d2=2 2 1
d3=1 3 1
d4=2 3 1
d5=1 2 4
d6=2 2 4
d7=1 3 4
d8=2 3 4
2) After that, how can i compute this equation F = X1(X2-X3) for all d?
For example d1=1 2 1 so is F1=1*(2-1)=1 etc.

採用された回答

Mohammad Abouali
Mohammad Abouali 2016 年 5 月 17 日
編集済み: Mohammad Abouali 2016 年 5 月 17 日
a=[1,2];
b=[2,3];
c=[1,4];
% Getting all the combinations
[x1,x2,x3]=ndgrid(a,b,c);
% reshaping them as a column vector;
x1=x1(:);
x2=x2(:);
x3=x3(:);
disp([x1 x2 x3])
1 2 1
2 2 1
1 3 1
2 3 1
1 2 4
2 2 4
1 3 4
2 3 4
% Calculating F as instructed.
F = x1.*(x2-x3)
F =
1
2
2
4
-2
-4
-1
-2
  2 件のコメント
Nik Sam
Nik Sam 2016 年 5 月 17 日
thanks a lot
Nik Sam
Nik Sam 2016 年 5 月 17 日
Can I ask for something else please?
Can we can a function that receives only a,b,c..,d,e,f etc as inputs and we can give the equation as inline function from command window?

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by