Help with code
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentarios
Jan
el 11 de Mayo de 2012
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
el 11 de Mayo de 2012
Sargondjani
el 11 de Mayo de 2012
the error is exactly what it says: RPairs had 1 row and 2 columns, so RPairs(:,3) does not exist....
Dr. Seis
el 11 de Mayo de 2012
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
el 11 de Mayo de 2012
Respuestas (0)
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!