필터 지우기
필터 지우기

Index exceeds matrix dimensions.

조회 수: 1 (최근 30일)
Emily Lubicich
Emily Lubicich 2015년 12월 21일
댓글: Austin 2015년 12월 21일
I am trying to create a covariance matrix for a class assignment. I loaded two columns of data x and y, each has 136 rows. I then entered "raw_data=[data_x(:,4),data_y(:,4)];cov_matrix=cov(raw_data)" based on my professors instructions and I get the error message Index exceeds matrix dimensions. I'm thinking this means I need to adjust the (:,4) part but I don't really know what it means so I don't know what to change it to.
  댓글 수: 1
Austin
Austin 2015년 12월 21일
Is there a fourth column in your data vectors? (:,4) can be read "the entry in all rows for column 4". If they are just nx1 then changing the 4 to 1 should work. Unless the cov() function works differently than I am assuming.

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

답변 (1개)

Chad Greene
Chad Greene 2015년 12월 21일
What is the size of data_x? You can check this by
size(data_x)
When you call data_x(:,4) it's trying to access all 136 rows of the fourth column in data_x. I suspect data_x may not have 4 columns. If data_x and data_y only have one column each, computing the covariance matrix will be easy:
cov_matrix=cov([data_x data_y])

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by