code running for infinite while plotting my array for correlation
Mostrar comentarios más antiguos
Hi,
I have problem as my code running for infinite time while I am plotting my arrays to achive coeffcient correlation.
here is my code:
for i=1:length(A)-300
Rx{i}= corrcoef(A (i:i+300), S(i:i+300));
Time_Rx=i;
B{1,i} = Rx(i)
C{1,i} = Time_Rx
end
(Aiming for plot Rx as a function over time)
plotting by using:
plot(B,C);
Can not figure out what is wrong, Any help would be appriciable.
20 comentarios
Walter Roberson
el 24 de Mzo. de 2019
Editada: Walter Roberson
el 24 de Mzo. de 2019
I see no evidence that it is running for infinite time. It is, though, doing a sliding window of correlation coefficients, sliding one further each time, and that operation could take some time. Are you sure that you want to slide only one each time?
Note that you are writing into cell arrays, but it is not permitted to plot() a cell array. Especially since it is a cell of cells -- you write into Rx{i} but you B{1,i} = Rx(i) and notice that Rx(i) is a 1 x 1 cell, not the result of the correlation coefficient but rather the cell wrapping the result of the correlation coefficient.
Walter Roberson
el 24 de Mzo. de 2019
L = length(A) - 300;
B = zeros(2,2,L);
for K = 1 : L
B(:,:,K) = corrcoef(A(i:i+300), S(i:i+300));
end
C = 1 : L;
But it is not clear what you mean by plotting C (the index) vs B (a 2 x 2 array for each location).
It might make some sense to use
L = length(A) - 300;
B = zeros(L, 4);
for K = 1 : L
cc = corrcoef(A(i:i+300), S(i:i+300));
B(K, :) = cc(:);
end
C = 1 : L;
plot(C, B)
legend({'(1,1)', '(2,1)', '(1,2)', '(2,2)'})
Bob
el 5 de Abr. de 2019
Walter Roberson
el 5 de Abr. de 2019
When you calculate correlation coefficient between two columns, then the result is always 2 x 2.
Perhaps,
L = length(A) - 300;
B = zeros(L, 1);
for K = 1 : L
cc = corrcoef(A(i:i+300), S(i:i+300))
B(K) = cc(2,1);
end
plot(B);
Bob
el 6 de Abr. de 2019
Walter Roberson
el 6 de Abr. de 2019
L = length(A) - 300;
B = zeros(L, 1);
for i = 1 : L
cc = corrcoef(A(i:i+300), S(i:i+300))
B(i) = cc(2,1);
end
plot(B);
Bob
el 6 de Abr. de 2019
Walter Roberson
el 6 de Abr. de 2019
cc(1,1) is correlation of the section of A relative to itself. cc(2,2) is the correlation of the section of S relative to itself. cc(1,2) and cc(2,1) are the correlation of each relative to the other.
... I'm not sure what you are asking to extract and plot?
Walter Roberson
el 8 de Abr. de 2019
p = polyfit(B,1);
hold on
t = 1 : length(A)-300;
plot(t, polyval(p, t), 'b-');
Bob
el 8 de Abr. de 2019
Walter Roberson
el 8 de Abr. de 2019
t = 1 : length(A)-300;
p = polyfit(t, B, 1);
hold on
plot(t, polyval(p, t), 'b-');
hold off
Bob
el 8 de Abr. de 2019
Walter Roberson
el 8 de Abr. de 2019
p = polyfit(t(:), B, 1);
Example code attached.
Bob
el 8 de Abr. de 2019
Walter Roberson
el 8 de Abr. de 2019
A (nearly) horizontal line looks plausible to me given that data. Area above looks like it mostly balances area below, and the decreasing variance towards the right side would tend to anchor the endpoint of the line in values close to that range.
Walter Roberson
el 8 de Abr. de 2019
"Can I plot B values at X axis and Z values at Y axis and in diffrent colors ?"
When would the different colors be triggered?
Your B values increase and decrease irregularly like you see on the first plot. It would not seem to make sense to use them as the X axis values.
When you talk about "and in diffrent colors" my first interpretation was that you were wanting to plot two different lines, one for B, and one for Z, but then talking about plotting them on the X and Y axis would not seem to make any sense. The closest I can find to make sense of that would be to do something like
NA = length(A);
ZERO = zeros(NA, 1);
t = 1 : NA
plot3(t, B, ZERO, 'k', t, ZERO, Z, 'b');
which plots them with a common time base and with two different lines, each along a different axes.
Bob
el 12 de Abr. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!