MATLAB Answers


code running for infinite while plotting my array for correlation

Asked by Bob
on 24 Mar 2019
Latest activity Commented on by Bob
on 12 Apr 2019
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));
B{1,i} = Rx(i)
C{1,i} = Time_Rx
(Aiming for plot Rx as a function over time)
plotting by using:
Can not figure out what is wrong, Any help would be appriciable.


"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.
[MOVED from flags] Bob wrote:
Worked well.
@Bob: Please use flags only to informa admins about inappropriate contents like rudeness or spam. Thanks.
Hi Walter,
How can I avraged my data (A anS) in minutes (for 10 minutes) before I do correlation calculation, in above code ??

Sign in to comment.

1 Answer

Answer by BERGHOUT Tarek on 6 Apr 2019
Edited by Walter Roberson
on 6 Apr 2019
 Accepted Answer

if you want to plot Rx , then you should plot B not C, and you can't plot B vs C in this example because C and B they dont have the same length ( dimensions are not the same), try this code , I hope that it is helpful:
clear all;
for i=1:length(A)-300
Rx=corrcoef(A (i:i+300), S(i:i+300));
B=[B Rx];

  1 Comment

Dear berghout,
How can I make a Linear plot of Rx values to visualize the all correlation points, either negative or positive correlation?

Sign in to comment.