i want to determine common sub sequence on array

7 Ansichten (letzte 30 Tage)
abduall hassn
abduall hassn am 29 Apr. 2015
Bearbeitet: abduall hassn am 3 Nov. 2016
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 Kommentare
Guillaume
Guillaume am 29 Apr. 2015
Bearbeitet: Guillaume am 29 Apr. 2015
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 am 29 Apr. 2015
@abduall hassn: Are the element values unique within each vector?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

pfb
pfb am 29 Apr. 2015
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 Kommentare
pfb
pfb am 29 Apr. 2015
the output of what I propose is
i = [ 1 2 3 9 10]
pfb
pfb am 29 Apr. 2015
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by