Find the rows have two same elements from a matrix

조회 수: 1 (최근 30일)
Jiafeng Ye
Jiafeng Ye 2022년 12월 11일
댓글: Torsten 2022년 12월 11일
I have a matrix (each row represents a traingle and each element represents a vertex ID of that traingle), I want to find which two traingles have two same vertices. This question can be demonstrated by the following example, for a matrix like the following:
1 9 8
2 7 8
5 8 9
6 5 4
7 3 8
5 4 8
the output would be [1, 3], [2, 5], and [3, 6], which are the rows have two same elements.
  댓글 수: 3
Jiafeng Ye
Jiafeng Ye 2022년 12월 11일
This is not a homework question but a research one.
Each row represents a trainlge (consists of three vertices).
Torsten
Torsten 2022년 12월 11일
A research is no homework ? Then you don't work at home for your research ?

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2022년 12월 11일
편집: Torsten 2022년 12월 11일
A = [1 9 8
2 7 8
5 8 9
6 5 4
7 3 8
5 4 8];
[I,J] = meshgrid(1:size(A,1),1:size(A,1));
[rows cols] = find(arrayfun(@(i,j)numel(intersect(A(i,:),A(j,:))),I,J)==2);
tuples = [rows(rows < cols),cols(rows < cols)]
tuples = 4×2
1 3 2 5 3 6 4 6

추가 답변 (1개)

Matt J
Matt J 2022년 12월 11일
편집: Matt J 2022년 12월 11일
Use edges to get a list of all the edges of the triangulation. Then loop over the list and use edgeAttachments.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by