All Possible Combinations of 2 vectors

1 Ansicht (letzte 30 Tage)
Gianluca Borgna
Gianluca Borgna am 19 Dez. 2018
Beantwortet: Stephen23 am 19 Dez. 2018
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

Akzeptierte Antwort

Stephen23
Stephen23 am 19 Dez. 2018
>> [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

Weitere Antworten (1)

KSSV
KSSV am 19 Dez. 2018
Read about nchoosek

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by