Help with code

Hi everybody, I am having some trouble with some code. My program goes through every substring within a string, finds out where it occurs, and stores the "post" pattern substring. Then it needs to take correlations of all the "post patterns" substrings so it needs to do correlation of all combinations and then take a average.
I would really appreciate if someone can help me. Here is my code (without the correlation part which I could do with some help....also theres a error when Im trying to store the post pattern substrings).
A = [1 2 2 2 1 2 3 4 1 2 2 2 2 1 2 3 4 1 1 1 1]
n=3; %n
x=3;
for i =1:length(A)-n+1
ZZ= strfind(A,A(i:i+n-1));
if (length(ZZ)==1)
C(i)=0;
end
if (length(ZZ)>1)
clear array;
index =1;
for j=1:length(ZZ)
array(:,index) = A(ZZ(j)+n:ZZ(j)+n+x);
index=index+1;
end
R=corrcoef(array);
RPairs = [nchoosek(1:size(array,2),2), nonzeros(tril(R,-1))];
M(i) = mean(RPairs(:,3))
end
end
I thank everyone for their contribution
ERROR: Attempted to access RPairs(:,3); index out of bounds because size(RPairs)=[1,2].
I am trying to get the average of the bottom traingular section of correlation matrix.

댓글 수: 5

Jan
Jan 2012년 5월 11일
Whenever you post in a forum, that there is an error, post a complete copy of the message also. While assisting to solve the cause of an error is a straight job, it is much harder to guess the the error itself. Thanks.
Mate 2u
Mate 2u 2012년 5월 11일
Thanks edited
Sargondjani
Sargondjani 2012년 5월 11일
the error is exactly what it says: RPairs had 1 row and 2 columns, so RPairs(:,3) does not exist....
Dr. Seis
Dr. Seis 2012년 5월 11일
You have a lot more code implementation problems than just this... not only have you hard-coded the number of columns to be 3 (your current error), you haven't taken into account that the indexes associated with "ZZ(j)+n:ZZ(j)+n+x" will at some point in your loop give you values greater than the "length(A)".
Mate 2u
Mate 2u 2012년 5월 11일
Could you help me then please.

답변 (0개)

이 질문은 마감되었습니다.

질문:

2012년 5월 11일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by