All Possible Combinations of 2 vectors
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gianluca Borgna
le 19 Déc 2018
Réponse apportée : Stephen23
le 19 Déc 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
0 commentaires
Réponse acceptée
Stephen23
le 19 Déc 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
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!