# code running for infinite while plotting my array for correlation

조회 수: 2 (최근 30일)
Bob 2019년 3월 24일
댓글: Bob 2019년 4월 12일
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이전 댓글 18개 표시이전 댓글 18개 숨기기
Jan 2019년 4월 11일
[MOVED from flags] Bob wrote:
Worked well.
@Bob: Please use flags only to informa admins about inappropriate contents like rudeness or spam. Thanks.
Bob 2019년 4월 12일
Hi Walter,
How can I avraged my data (A anS) in minutes (for 10 minutes) before I do correlation calculation, in above code ??

댓글을 달려면 로그인하십시오.

### 채택된 답변

BERGHOUT Tarek 2019년 4월 6일
편집: BERGHOUT Tarek 2019년 4월 6일
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;
clc;
%%%
t=1:600;
A=0.25;
B=1.25;
f1=0.5;
f2=0.025;
S=A*sin(f1*t)+B*cos(f2*t)+wgn(size(t,1),size(t,2),3);
A=S+randn(size(S));
%%%
B=[];
for i=1:length(A)-300
Rx=corrcoef(A (i:i+300), S(i:i+300));
B=[B Rx];
end
plot(1:size(B,2),B);
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Bob 2019년 4월 6일
Dear berghout,
How can I make a Linear plot of Rx values to visualize the all correlation points, either negative or positive correlation?

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by