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
0 件のコメント
採用された回答
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
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!