All possible combinations of variables

조회 수: 7 (최근 30일)
Josep
Josep 2014년 8월 5일
편집: Star Strider 2014년 8월 13일
Hey everybody,
I have a system with x variables and I want to obtain by using MATLAB a combination of all of them in all the possible groups. Let me introduce you an example:
Lets suppose I have 6 variables for example(1,2,3,4,5,6), it means there will be 63 combinations without repeating any. My aim is to achieve all the combinations like this:
[1] [2] [3] [4] [5] [6]
[1,2] [1,3] [1,4] [1,5] [1,6] [2,3] [2,4] ...
[1,2,3] [1,2,4] [1,2,5] [1,2,6] [1,3,4] [1,3,5] [1,3,6] [1,4,5] [1,4,6] [1,5,6] [2,3,4] ....
and the same for groups of 4, 5 and 6 variables.
Does anybody know how to do it for X number of variables? I need to do this to compute an statistics equation in order to detect errors in the measured values of the system.
Thank you for your attention!
  댓글 수: 2
Andrew Reibold
Andrew Reibold 2014년 8월 5일
Do you just need to know 'how many' combinations there are, or do you need all of the combinations output. If you need them output, how should they be displayed or stored?
Josep
Josep 2014년 8월 5일
No, I need all of the combinations output. Could I email you in order to be more explicit?
Thank you!

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

채택된 답변

Star Strider
Star Strider 2014년 8월 5일
편집: Star Strider 2014년 8월 5일
If you have the Statistics Toolbox, use the combnk function:
v = 1:6;
c2 = combnk(v,2)
c3 = combnk(v,3)
... and so on for 4, 5, and 6.
  댓글 수: 24
Josep
Josep 2014년 8월 13일
I have done this:
function combo = combs(6,2)
combinator(n,k,'c'); % Combinations without repetition
combo = ans;
end
And I still have an error message:
>> combs(6, 2) Error: File: combs.m Line: 2 Column: 24 Unexpected MATLAB expression.
Star Strider
Star Strider 2014년 8월 13일
편집: Star Strider 2014년 8월 13일
That’s strange. Line 2 is the combinator call, and column 24 is in the comment!
I’ll download combinator in a few minutes to see if I can replicate your error.
Later that same day ...
I downloaded combinator, saved it to my user directory, and ran this code:
combinator(6,2,'c'); % Combinations without repetition
combo = ans;
without problems, returning combo as a (15x2) double matrix. I have no idea what may be the problem with your code, or perhaps with your MATLAB installation.
I still suggest you run this command from the Command Window:
which combinator -all
and copy the results to a comment to this thread.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by