Showing every possibility of each index in a matrix

2 次查看(过去 30 天)
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 个)

Image Analyst
Image Analyst 2020-1-26
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.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by