필터 지우기
필터 지우기

How can I generate the matrix [1 1; 1 2; 1 3 ; 2 1; 2 2; 2 3; 3 1 ; 3 2 ; 3 3] without loops?

조회 수: 1 (최근 30일)
And given matrices XX and YY of sizes 3X3, how can I generate the following matrix:
[XX(1,1) YY(1,1); XX(1,2) YY(1,2);XX(1,3) YY(1,3); XX(2,1) YY(2,1); XX(2,2) YY(2,2); XX(2,3) YY(2,3); XX(3,1) YY(3,1); XX(3,2) YY(3,2); XX(3,3) YY(3,3)]
I mean of course, without writing it explicitly.
Thanks!!

채택된 답변

C.J. Harris
C.J. Harris 2012년 11월 15일
I have no idea what your data is, but to generate the matrix in the question try:
out = unique(nchoosek([1:3, 1:3], 2), 'rows');

추가 답변 (2개)

Andreas Goser
Andreas Goser 2012년 11월 15일
?? "Just telling me how to generate the matrix in the title would be a huge help!" ??
a=[1 1; 1 2; 1 3 ; 2 1; 2 2; 2 3; 3 1 ; 3 2 ; 3 3]

Jos (10584)
Jos (10584) 2012년 11월 15일
COMBN!
combn(1:3,2)
ans =
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by