I have many such matrices(whose dimension are all 3*3.) like:


Their corners is all $0$.I show they with two dimension format.

As you can see they have some repeated elements(Just can have two repeated elements between two matrices).I want to combine it in this order$ \left(\begin{matrix} list1&list2\\list3&list4 \end{matrix} \right) $.in this case,that is: $$\left( \begin{array}{cccc} 0 & 3 & 6 & 0 \\ 4 & 1 & 2 & 8 \\ 9 & 5 & 7 & 10 \\ 0 & 11 & 12 & 0 \\ \end{array} \right)$$ In this simple case,we can know its order should be $ \left(\begin{matrix} list1&list2\\list3&list4 \end{matrix} \right) $ after a glance.But in the real case,I just know their neighbouring relations like


Any elegant method can do this?

  • 1
    $\begingroup$ so you have a set of 3x3 matrices, and you want for example to join two matrices side by side if the right element of the left one is equal to the central element of the right one, and the left element of the right one is equal to the central element of the left one? In general, the "extremal" elements should flag to which other matrices can a matrix be joined, "selecting" all the matrices with the correct central element. Correct? $\endgroup$
    – glS
    Oct 20, 2016 at 11:24
  • 1
    $\begingroup$ As @gls point out, for 3x3 matrix it is rather simple. If you have a large matrix, you can convert it into Image[] and use this answer to find the matching edges. $\endgroup$
    – Sumit
    Oct 20, 2016 at 11:50
  • 1
    $\begingroup$ @Sumit or this: mathematica.stackexchange.com/q/32612/5478 $\endgroup$
    – Kuba
    Oct 20, 2016 at 12:03
  • $\begingroup$ @glS Yes,they are all 3*3 $\endgroup$
    – yode
    Oct 20, 2016 at 16:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.