MATLAB question: N-combinations of sections of arrays
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:
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.
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.
0
Comments
I did, however, also run into an error trying to name my string cells with the following bit of code:
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.