Effacer les filtres
Effacer les filtres

Index exceeds matrix dimensions.

1 vue (au cours des 30 derniers jours)
Emily Lubicich
Emily Lubicich le 21 Déc 2015
Commenté : Austin le 21 Déc 2015
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 commentaire
Austin
Austin le 21 Déc 2015
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.

Connectez-vous pour commenter.

Réponses (1)

Chad Greene
Chad Greene le 21 Déc 2015
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])

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by