Finding a redundant pattern in a matrix

조회 수: 3 (최근 30일)
Annaelle
Annaelle 2023년 1월 26일
댓글: Annaelle 2023년 1월 30일
Hi,
I'm trying to compare a serie of number in a matrix of cells to see if some pattern are redondant.
The issue is that the pattern needs to be in the same order but it can be broken by another number.
For example : C1=[ 5 9 3]; C2=[ 9 5 3]; C3=[9 5 9 3]; C4=[5 9 8 3]; ...
In this case, I want to know that the pattern in C1 is repeated in C3 and C4 ... then do the same for C2.
Thanks for your help
Anna
  댓글 수: 1
Image Analyst
Image Analyst 2023년 1월 26일
편집: Image Analyst 2023년 1월 26일
What's the use case (context as to why that is needed)? Have you tried a brute force search via a nested for loop? That would be pretty simple and fast for short vectors.

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 26일
C1=[ 5 9 3]; C2=[ 9 5 3]; C3=[9 5 9 3]; C4=[5 9 8 3]; C5 = [5 3 9 8];
is_in(C1, C2)
ans = logical
0
is_in(C1, C3)
ans = logical
1
is_in(C1, C4)
ans = logical
1
is_in(C1, C5)
ans = logical
0
function match = is_in(looking_for, in_what)
match = all(any(triu(looking_for.' == in_what),2));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by