Repeated event in a array

1 回表示 (過去 30 日間)
Mate 2u
Mate 2u 2012 年 5 月 4 日
Hi there, I have a vector of size 10,000,000 x 1. The vector has inputs of 1 0 and -1 only. I want to find repeated events.
For instance 1 1 0 1 1 -1 -1 1 , I want to test if this exact same elements have appeared again in the data.
If so I would like a graph to represent the whole data plus the pattern in a colour.
Looking forward to a answer. Thanks.
  2 件のコメント
Jan
Jan 2012 年 5 月 4 日
The question is not clear.
Your input is in = [1 1 0 1 1 -1 -1 1];
What is the wanted output? What are "repeated events"? What kind of graph do you want? For a suggestion how to draw a pattern in color, we have to knwo, what a "pattern" is in your case.
Mate 2u
Mate 2u 2012 年 5 月 4 日
Ok here is a example... A = [ 1 0 1 0 1 1 1 -1 -1 1 0 1 0 1 0 -1 -1]
And if I want to search for 1010, it will plot a graph and whereever there is 1 0 1 0 in order it will come out coloured in that part of the graph

サインインしてコメントする。

採用された回答

Daniel Shub
Daniel Shub 2012 年 5 月 4 日
Loren talks about findings patterns in arrays.
Processing your example
A = [1 0 1 0 1 1 1 -1 -1 1 0 1 0 1 0 -1 -1];
x = [1 0 1 0];
with Loren's method would give
[1 10 12]
This can then be plotted with
stem(A);
hold on;
arrayfun(@(n)stem((0:3)+n, A((0:3)+n),'r'), [1, 10, 12]);
  3 件のコメント
Daniel Shub
Daniel Shub 2012 年 5 月 4 日
yes.
Mate 2u
Mate 2u 2012 年 5 月 4 日
Is there a way where I can only plot the matched elements + the next 20 elements of the full array?
So for example, forget plotting everything, just plot what was found and then do seperate plots for each but with each one continuing for a certain period?

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2012 年 5 月 4 日
Are you looking for neighboring elements with equal values? Then use diff. Are you looking for a specific patter, use strfind(data, [1 1 0 1 1 -1 -1 1]).
  2 件のコメント
Mate 2u
Mate 2u 2012 年 5 月 4 日
You are right, but is there a way to plot it so that the repeated parts are in different colour?
Mate 2u
Mate 2u 2012 年 5 月 4 日
Thank you Jan! You were very helpful! Sorry if I was not clear enough.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by