Filter löschen
Filter löschen

All possible combinations of variables

11 Ansichten (letzte 30 Tage)
Josep
Josep am 5 Aug. 2014
Bearbeitet: Star Strider am 13 Aug. 2014
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 Kommentare
Andrew Reibold
Andrew Reibold am 5 Aug. 2014
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 am 5 Aug. 2014
No, I need all of the combinations output. Could I email you in order to be more explicit?
Thank you!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 5 Aug. 2014
Bearbeitet: Star Strider am 5 Aug. 2014
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 Kommentare
Josep
Josep am 13 Aug. 2014
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 am 13 Aug. 2014
Bearbeitet: Star Strider am 13 Aug. 2014
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by