MATLAB question: N-combinations of sections of arrays

edited May 2006 in Internet & Media
So I've got a 2x4 matrix which I want to use to generate a larger matrix consisting of all 2-combinations of the 4 2x1 portions of the 2x4 matrix.

Example with 2x3:
[A X]
[B Y]
[C Z]

Which I want to turn into, using nchoosek()

[A X B Y]
[A X C Z]
[B Y C Z]

Or at least generate three seperate arrays with the same information, which I can then vertically concatenate.

Unfortunately, nchoosek() will only operate on individual elements. So, I tried to set the pairs of elements equal to variables, and then use an array of those variables:

I = [A X]
J = [B Y]
K = [C Z]

...and then using nchoosek on:

[J]
[K]

Unfortunately, this just evaluates to the original 2xN array.

I then tried making the 2x1 arrays into strings, combining them them, and then re-evaluating them the the original values. Unfortunately, nchoosek doesn't work on string arrays for some reason.

So, any ideas of how I can force Matlab to not evaluate the variables, combine sets of elements, or do N-combinations of strings?

Thanks.

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited May 2006
    check the matlab help for "cell" and let me know if you need any more help than that. You'll want to add I,J,K to a cell array and call nchoosek on the cell array.
  • edited May 2006
    That worked perfectly. Thanks for the help.

    I did, however, also run into an error trying to name my string cells with the following bit of code:
    for i = 1:numberOfBets
        strcat('pWP',num2str(i)) = cellstr(mat2str(cat(2,bookiePayoffs(1,i)',expertProbabilities(1,i)')))
    end
    

    Can I not do an assignment or equality like that? Both sides of the equality evaluate fine individually, but when I set them equal to each other I get a 52x52 array with the correct data strewn among a field of zeros.
Sign In or Register to comment.