Filter löschen
Filter löschen

Showing every possibility of each index in a matrix

1 Ansicht (letzte 30 Tage)
Hardi Mohammed
Hardi Mohammed am 26 Jan. 2020
Beantwortet: Image Analyst am 26 Jan. 2020
I am trying to find out all the possibility of Matrix index. but I have problem for example:
A=[ 1 2 3;
4 5 6;
7 8 9];
Here we have six possibilities
1 5 9
1 6 8
2 4 9
2 6 7
3 5 7
3 4 8
The above rows are the possibilities of A matrix. I am trying to get a matrix with all these possiblities but I have problem. Does someone know how we can do it in MATLAB?
  1 Kommentar
Mohammad Sami
Mohammad Sami am 26 Jan. 2020
Bearbeitet: Mohammad Sami am 26 Jan. 2020
Would the number of possibilities be n factorial for n x n matrix ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 26 Jan. 2020
Sounds like homework so I'll just give a hint. If it's not homework, say so.
The list seems to start only with elements on the first row and include elments on the second and third row only if the column is not the same as the column that the element in the top row is. Put in a counter and an if with a continue if the column is the same. Here's a start
topRow = A(1, :);
[rows, columns] = size(A)
counter = 1
results = zeros(1, columns); % Initialize
for col = 1 : columns
for row2Col = 1 : columns
if ........
continue
end
for row3Col = 1 : columns
if ............
continue; % Skip
end
% String together all elements that we've found that meet criteria.
results(counter, :) = [A(1, col), A(2, row2Col), A(3, row3Col)]
counter = counter + 1;
end
end
end
results % Report to command window.
If you're going to earn credit for the answer, you should at least be able to figure out what to put after the if.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by