generating matrices of the possible combinations
이전 댓글 표시
How do I find all the possible matricies (not their number but the matricies themselves) that are formed as a result of taking a combination of a certain number of columns y from a matrix with a total number of columns x ?
example
X = 1 7 9 10 15
4 8 5 9 21
2 14 3 6 16
here X is 3 by 5 ( 5 columns), now suppose I want to obtain the MATRICIES THEMSELVES that are the result of mixing any of the 3 columns of matrix X
In this case 5c3 , i should obtain 10 matricies, how do I get them ?
댓글 수: 1
Luna
2018년 12월 6일
Do you want to get 3x3 matrices?
채택된 답변
추가 답변 (1개)
Luna
2018년 12월 6일
Try this;
M is a 1x10 cell array which contains 3x3 matrices chosen from the X.
X = [1 7 9 10 15
4 8 5 9 21
2 14 3 6 16]
A = nchoosek(X(1,:),3)
B = nchoosek(X(2,:),3)
C = nchoosek(X(3,:),3)
for i = 1:nchoosek(5,3)
M{i} = [A(i,:);B(i,:);C(i,:)];
end
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!