Azzera filtri
Azzera filtri

Index exceeds matrix dimensions.

1 visualizzazione (ultimi 30 giorni)
Emily Lubicich
Emily Lubicich il 21 Dic 2015
Commentato: Austin il 21 Dic 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 Commento
Austin
Austin il 21 Dic 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.

Accedi per commentare.

Risposte (1)

Chad Greene
Chad Greene il 21 Dic 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])

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by