could anyone help me to solve the issue

2 Ansichten (letzte 30 Tage)
jaah navi
jaah navi am 13 Sep. 2019
Kommentiert: jaah navi am 17 Sep. 2019
AA=4
I am having matrix as below
A=[2 3;
1 4;
2 4;
3 4]
with respect to first row out of four i am having two numbers 2 and 3.
so i need to have an another variable B in the following manner
B={2 3} {1 4} for first row
{1 4} {2 3} for second row
{2 4} {1 3} third row
{3 4} {1 2} fourth row
could anyone please help me on it.
  1 Kommentar
Adam
Adam am 13 Sep. 2019
Can you please try to give a more relevant title to your questions in general. Almost every question you ask you just give the same generic title. The question box should be for a short summary of what your question is about. Every question on the board could be titled 'Can you please help with this', but it isn't very useful for people scanning the questions for ones they may be able to contribute to.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 13 Sep. 2019
Easy enough. Just use setdiff.
A=[2 3;
1 4;
2 4;
3 4];
That is, ...
B = A;
cind = [3 4];
for i = 1:4
B(i,cind(randperm(2))) = setdiff(1:4,B(i,1:2));
end
B is:
B
B =
2 3 4 1
1 4 2 3
2 4 1 3
3 4 1 2
  1 Kommentar
jaah navi
jaah navi am 17 Sep. 2019
The above code works for the matrix
A=[2 3;
1 4;
2 4;
3 4];
could you please help me how it can be done for the following matrix
A=[2 3;
1 4;
2 4];

Melden Sie sich an, um zu kommentieren.

Weitere 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