Showing every possibility of each index in a matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Mohammad Sami
il 26 Gen 2020
Modificato: Mohammad Sami
il 26 Gen 2020
Would the number of possibilities be n factorial for n x n matrix ?
Risposte (1)
Image Analyst
il 26 Gen 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!