Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB - matrix combinations

Tags:

matlab

I am fairly new to MATLAB and I am having trouble figuring out an efficient solution for a problem. Any help would be greatly appreciated!!

I have a 2D matrix containing various angles between lines that looks like

            L1  L2 L3 L4 L5 L6
         L1  0  40 90 0  10 0 
         L2  40 0  0  5  40 20 
         L3  90 0  0  45 0  10 
         L4  0  5  45 0  10 15 
         L5  10 40 0  10 0  15 
         L6  0  20 10 15 15 0

Note that each corresponding column/row are identical. I need to find all of the possible combinations that the lines could be organized in the matrix. ie L1 L2 L3 L4 L5 L6, L1 L2 L3 L4 L6 L5, L1 L2 L3 L5 L6 L4, etc. I need to generate a matrix for each combination that will be compared with template values later.

I attempted to use

p = perms(1:6);
tp = angles( p, : );

to just swap the matrix's rows for each combination. This works fine, except that only the rows are swapped for each combination, when column also needs to be swapped.

             L1 L2 L3 L4 L5 L6                 L1 L2 L3 L4 L6 L5
         L1  0  40 90 0  10 0              L1  0  40 90 0  0  10 
         L2  40 0  0  5  40 20             L2  40 0  0  5  20 40 
         L3  90 0  0  45 0  10  should be  L3  90 0  0  45 10 0 
         L4  0  5  45 0  10 15             L4  0  5  45 0  15 10
         L6  0  20 10 15 15 0              L6  0  20 10 15 0  15
         L5  10 40 0  10 0  15             L5  10 40 0  10 0  0
like image 931
Mav3rick Avatar asked Jun 30 '26 19:06

Mav3rick


1 Answers

For permutation num, use tp = angles(p(num,:),p(num,:)) which permutes both the row and column to give for your example permutation [1 2 3 4 6 5]:

tp =

     0    40    90     0     0    10
    40     0     0     5    20    40
    90     0     0    45    10     0
     0     5    45     0    15    10
     0    20    10    15     0    15
    10    40     0    10    15     0

which is what I think you really require. Your "should be" is not longer symmetric, which can't be right.

like image 197
Ramashalanka Avatar answered Jul 02 '26 10:07

Ramashalanka