フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by