MATLAB: How can i create matrix for all possible combination

all possible combination

phi= [0.05, 0.1, 0.2, 0.5]
delta= [0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 3.0]
I do need to create 4×7 =28 different combination. so final matrix should be
[0.05 0.05 ;0.05 0.1 ;0.05 0.25;.....]
something like this how can i create?

Best Answer

Use ndgrid:
>> [deltaM,phiM] = ndgrid(delta,phi);
>> [phiM(:),deltaM(:)]
ans =
0.05 0.05
0.05 0.1
0.05 0.25
0.05 0.5
0.05 1
0.05 2
0.05 3
0.1 0.05
0.1 0.1
0.1 0.25
0.1 0.5
0.1 1
0.1 2
0.1 3
0.2 0.05
0.2 0.1
0.2 0.25
0.2 0.5
0.2 1
0.2 2
0.2 3
0.5 0.05
0.5 0.1
0.5 0.25
0.5 0.5
0.5 1
0.5 2
0.5 3
Related Question