How to select all subset of rows of a matrix given the size of subset

조회 수: 4 (최근 30일)
Christos
Christos 2012년 12월 2일
Hi, i want to select all possible submatrices of rows -subsets of a matrix given the size of subset. i.e if i have the matrix X=[1 2 3;4 5 6; 7 8 9] i want to give k=2 (for example) and get
x1=[1 2 3;4 5 6] x2=[1 2 3;7 8 9] x3=[4 5 6;7 8 9].
This is an example. Is there a built-in or something for this?

답변 (1개)

Matt J
Matt J 2012년 12월 2일
Use NCHOOSEK
  댓글 수: 2
Christos
Christos 2012년 12월 2일
nchoosek returns the number of possible drawings n from k. I dont see how i could use it.
Matt J
Matt J 2012년 12월 2일
편집: Matt J 2012년 12월 3일
It can also perform drawings, as shown in the following example in which I compute all of the length k=2 drawings of 1:n, with n=4. You should ponder how this could be applicable to you.
>> nchoosek(1:4,2)
ans =
1 2
1 3
1 4
2 3
2 4
3 4

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by