フィルターのクリア

Showing every possibility of each index in a matrix

2 ビュー (過去 30 日間)
Hardi Mohammed
Hardi Mohammed 2020 年 1 月 26 日
回答済み: Image Analyst 2020 年 1 月 26 日
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 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 1 月 26 日
編集済み: Mohammad Sami 2020 年 1 月 26 日
Would the number of possibilities be n factorial for n x n matrix ?

サインインしてコメントする。

回答 (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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by