Patterns in matlab
1 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!