Borrar filtros
Borrar filtros

Index exceeds matrix dimensions.

1 visualización (últimos 30 días)
Emily Lubicich
Emily Lubicich el 21 de Dic. de 2015
Comentada: Austin el 21 de Dic. de 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 comentario
Austin
Austin el 21 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Chad Greene
Chad Greene el 21 de Dic. de 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])

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by