필터 지우기
필터 지우기

i want to determine common sub sequence on array

조회 수: 2 (최근 30일)
abduall hassn
abduall hassn 2015년 4월 29일
편집: abduall hassn 2016년 11월 3일
i want find common sub sequence from sequence output should be like
1,2,3
9,10
if we look 1,2,3 is common sub sequence between all array and also 9,10
  댓글 수: 2
Guillaume
Guillaume 2015년 4월 29일
편집: Guillaume 2015년 4월 29일
I'd recommend that you read this wikipedia page on the problem and code the algorithm described there.
Possibly, there's also something on fileexchange.
Stephen23
Stephen23 2015년 4월 29일
@abduall hassn: Are the element values unique within each vector?

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

채택된 답변

pfb
pfb 2015년 4월 29일
You can use the builtin function "intersect"
i = intersect(a,b);
i = intersect(i,c);
[...]
i = intersect(i,h)
The last i should contain only the elements common to all sequences.
If your sequences have all the same length, you can put them in a matrix, and loop over its rows. Otherwise you can build a cell array, so that you can loop, as opposed to writing one instruction for each intersection you need to do.
  댓글 수: 2
pfb
pfb 2015년 4월 29일
the output of what I propose is
i = [ 1 2 3 9 10]
pfb
pfb 2015년 4월 29일
mmm, perhaps now I get it... you want the common sub-sequences (plural).
Not sure my solution is the optimal one, but it contains what you're looking for.
You can break the sub sequences by checking the difference between adjacent elements in i.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by