开发者

MATLAB - matrix combinations

开发者 https://www.devze.com 2022-12-21 05:09 出处:网络
I am fairly new to MATLAB and I am having trouble figuring out an efficient solution f开发者_如何学运维or a problem. Any help would be greatly appreciated!!

I am fairly new to MATLAB and I am having trouble figuring out an efficient solution f开发者_如何学运维or 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消