How to Generate a Matrix of Specific Row-Column Combinations (to list certain permutations) Without Using Loops

1 view (last 30 days)
I want to create a matrix of specific row-column combinations. The rows should be considered pair-wise, and the columns should be the three columns that follow. So, this is like a setup for me to compare each pair of rows with all the pairs of rows in the three columns that follow. I do not want to use a loop, because my matrix is very large.
For example, let’s say that I have a matrix:
[a b c d;
e f g h;
i j k l;
m n o p]
So, the final matrix will look like this (hyphens for clarity): // Note that the first element after each hyphen/brace corresponds to the element in the row-pair being considered, while the three elements that follow belong to the three columns that follow. This means that the pair of elements in the row-pairs being considered are replicated in the final matrix.
[a b c d b c d NaN c d NaN NaN d NaN NaN NaN;
// NaNs because there arent column numbers 5:7 in the original matrix.
// The matrix I have will be very large (with 10000s of rows and columns) and so will actually need NaN's only towards the very last columns.
e f g h f g h NaN g h NaN NaN h NaN NaN NaN;
a j k l b k l NaN c l NaN NaN d NaN NaN NaN;
e n o p f o p NaN g p NaN NaN h NaN NaN NaN;
i b c d j c d NaN k d NaN NaN l NaN NaN NaN;
m f g h n o p NaN o h NaN NaN p NaN NaN NaN;
i j k l j k l NaN k l NaN NaN l NaN NaN NaN;
m n o p n o p NaN o p NaN NaN p NaN NaN NaN]
Does anyone have ideas on how to get this done? I tried using repelem and repmat, but I cannot think of a way to get rows pairwise (in the way that one can get odd rows using (1:2:end, :), for example). Thank you for your time!
  1 Comment
Image Analyst
Image Analyst on 22 Mar 2016
Can you also give an example with actual numbers and no dashes or comments? I don't know what "compare" means to you (e.g. subtraction) and don't know if all "-" are hyphens or minus signs.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!