MATLAB: All Possible Combinations of 2 vectors

combinationsMATLAB

Hi everybody,
I have a simple question.
I'm trying to generate rapidly a matrix with all combinations of 2 vectors.
I'm working on the classification of bridge damages. The damage is expressed with a qualitative number ranging from 1 to 5 (the first vector) CR=1:5, the other vector is the position of damage on the bridge ranging also it from 1 to 5 (a fifth of the length per time).
I just would like to have the matrix that containts as the number of rows the combinations of CR, and as the number of columns the ith position.
I would like to have a scheme to follow.
It should look like:
A=[1 1 1 1 1; 2 1 1 1 1; ..; 3 4 5 1 1; …]
excluding the repetitions.
I tried different commands but i'm not finding the solution!
Thanks in advance!
G

Best Answer

>> [A,B,C,D,E] = ndgrid(1:5);
>> M = [A(:),B(:),C(:),D(:),E(:)];
M =
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 1 1 1
5 1 1 1 1
1 2 1 1 1
2 2 1 1 1
3 2 1 1 1
... lots of lines here
2 4 5 5 5
3 4 5 5 5
4 4 5 5 5
5 4 5 5 5
1 5 5 5 5
2 5 5 5 5
3 5 5 5 5
4 5 5 5 5
5 5 5 5 5