How to rearrange matrix with the given matrix?

조회 수: 2 (최근 30일)
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2022년 1월 9일
답변: Walter Roberson 2022년 1월 9일
Hi
let consider, we have a given matrix.
Initial given matrix:
columns
rows 2 5
4 3
1 6
7 8
I want to reshape or rearrange matrix.(it can return any matrix but it should not have pair (2,5),(4,3),(1.6),(7,8)). But should able to re-generate for test validity. The matrix which i want or expected is
columns
rows 2 3/1/6/7/8 (any value but not 5) (let i select 6)
4 5/1/7/8 (any value but not 3, (2,6)) (let I select 8)
1 3/5/7 (any value but not 6,(2,6),(4,8)) (let I select 5)
7 3 (only one value left )
So the above matrix look like:
columns
rows 2 6
4 8
1 5
7 3
  댓글 수: 1
Rik
Rik 2022년 1월 9일
There is no guarantee there is a solution for every input.
What did you try yourself?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 9일
circshift() the second column.
Or use trial and error:
V = [5; 3; 6; 8];
pV = perms(V);
valids = pV(all(pV ~= V.',2), :)
valids = 9×4
8 6 3 5 8 6 5 3 8 5 3 6 6 8 3 5 6 8 5 3 6 5 8 3 3 8 5 6 3 6 8 5 3 5 8 6

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by