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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!