Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Help with code
1 visualización (últimos 30 días)
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
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)".
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!