All Possible Combinations of 2 vectors

1 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2018-12-19
>> [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

更多回答(1 个)

KSSV
KSSV 2018-12-19
Read about nchoosek

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by