Patterns in matlab

1 次查看(过去 30 天)
Mate 2u
Mate 2u 2012-5-7
Hi all,
Thank you so much for your help on the forum. I need help. I have some data and I want to check each substring within the data (Value n) and then check if pattern occurs more than once, and if the pattern occurs more than once to calculate the correlation (Value X) of the number of elements after the substring has occured.
For example for an array A:
A = [1 2 2 2 1 2 3 4 1 2 2 2 2 1 2 3 4]
As n = 2. We check every sub-string of size 2. So it checks [1 2], [2 2], [2 2], [2 1].......up to [3 4].
now lets check the first substring which is [1 2]....as X is 2 it will give correlation of 2 values which occur after the pattern at all positions.
eg FIRST output in ARRAY Z would be correlation of [2 2] vs [3 4] vs [2 2] vs [3 4]
Then it will consider the second substring [2 2]
I have a work in progress code as follows
A = [1 2 2 2 1 2 3 4 1 2 2 2 2 1 2 3 4]
n=2; %n
X=2;
for i =1:length(A)-n+1
ZZ= strfind(A,A(i:i+n-1));
if length(ZZ)=1
C(i)=0;
else
for j=1:length(ZZ)
C(i)=corrcoef(
%%This is where I need help.
end
Thank you so much.
  2 个评论
Image Analyst
Image Analyst 2012-5-8
What the heck is X? It's not used in your code and I didn't understand your explanation of it. Also I don't know what this means: "correlation of [2 2] vs [3 4] vs [2 2] vs [3 4]". As far as I know you correlate one signal against another signal, and thatdoesn't seem what you're doing. Plus correlation (like from xcorr(), xcorr2(), or normxcorr2()) is different than the correlation coefficient (the corrcoeff() function you used.) Bottom line: I don't know what you want.
Sargondjani
Sargondjani 2012-5-8
i thought it was just me who didnt understand...

请先登录,再进行评论。

回答(1 个)

KUSHAL
KUSHAL 2012-11-1
Even I didn't understand what you need exactly. Kindly put your question neatly and what are your requirements and inputs given for that.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by