How to average sequential chunks of one vector based on the criteria of another
Mostrar comentarios más antiguos
Good Afternoon,
Working with a time vector, EChr (values 0-23.5, in 0.5 increments), and another vector, A, I need to average the values of A around each midnight (i.e., 0.0), leaving the rest of the values NaNed.
My code (below) would be fine if EChr didn't have breaks in the half-hour sequence. This is not the case.
How can I code this to bracket chunks surrounding each midnight (i.e., 0.0) based on the actual values of EChr, not the indices of EChr?
Lastly, this will surely get me an out of bounds error sooner or later. How can this be avoided?
for i=1:length(EChr)
if EChr(i)==0.0 % 0.0= midnight
A(i)=nanmean(A(i-4:i+6)); % 0.5 hour steps; 2 hours before midnight and 3 hours after midnight (i.e., 22.0-3.0)
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices 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!