Re-arrange matrix row elements so that a specific condition is fulfilled

1 Ansicht (letzte 30 Tage)
Say we have matrix
A =
1 2 3
1 3 5
1 2 4
2 3 7
The task is the re-arrange the row elements so that in no row 2 elements are in same order. For example rows 1 and 2 both have elements 1 and 3 so that three is after one. We can fliplr row 2 indices 1:2 and we get row 3 1 5. This has to be done for all rows. The problem in my algorithm is that it is slow and it ends up flipping some rows 3 times and some indices are again in the same order as in some rows.. Maybe this could be done with Answer Set Programming..
I have attached a matrix of 25 rows as test data
  2 Kommentare
Walter Roberson
Walter Roberson am 1 Mai 2019
My suspicion is that in the general case you may need to backtrack. There is a temptation to start at the top and keep all the rows that work moving from top to bottom, but I have a suspicion that if you do that you might force contradiction on some of the rows that do not originally work. I suspect that you might need to deliberately dearrange some of the "good" entries.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by