Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help with code

조회 수: 2 (최근 30일)
Mate 2u
Mate 2u 2012년 5월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
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
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개)

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

Community Treasure Hunt

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

Start Hunting!

Translated by