How do I fix the error "Subscripted assignment dimension mismatch" that happens when I execute this for loop?

I'm trying to write a for loop that computes the correlation coefficient between the windspeed at midnight on January 20th and the windspeed at each of the following 24 hours and store the correlation coefficients in a vector named wind_corrs. I'm having trouble with the for loop because every time I execute it, it says "Subscripted assignment dimension mismatch". Here is the code below:
hours = 456:1:480
for i = 1:length(hours)
wind_corrs(i) = corrcoef(hourly_windspeeds(:,456),hourly_windspeeds(:,456 + i));
end

1 comentario

Without seeing your code, about the best we can say is "Don't do that."
Check the size of what it is trying to assign. Check the size of what you are attempting to assign into.

Iniciar sesión para comentar.

 Respuesta aceptada

corrceof of two columns of data will return a 2 x 2 output. You are trying to store that 2 x 2 output into a single location.
For two real-valued vectors, the 2 x 2 should have 1 on the major diagonal and be symmetric on the anti-diagonal, so you could save the 2 x 2 to a variable and extract the appropriate value to store.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by