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

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2019-5-1
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by