필터 지우기
필터 지우기

Index exceeds array bounds from CorrCoeff

조회 수: 1 (최근 30일)
cniv_we
cniv_we 2019년 8월 19일
댓글: cniv_we 2019년 8월 19일
I am trying to calculate cumulative correlation coefficient matrix from 2 different arrays saved in matrix X
Now I only need to save the correlation coefficient in position (1,2) as corrcoeff typically gives 2x2 elements. However, I got this error code: Index in position 2 exceeds array bounds (must not exceed 1).
What's wrong with code below?
for b = 1:1000
corr_coeff = corrcoef(X(1:b,1),X(1:b,2)) % Calculate the cumulative corr.coeff between X(1:b) of column 1 and X(1:b) of column 2
CC(b,:) = [b corr_coeff(1,2)];
end
When I do not give the command CC(b,:) = [b corr_coeff(1,2)]; I don't have any problem?

채택된 답변

the cyclist
the cyclist 2019년 8월 19일
The problem is that in the first iteration of your loop, you are taking the correlation of two scalar values:
corrcoef(X(1,1),X(1,2))
which will just give the value 1, not a 2x2 matrix.
Maybe start your loop from b=2?
  댓글 수: 1
cniv_we
cniv_we 2019년 8월 19일
Ah alright, that works. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by