How to use a loop for an array
Mostrar comentarios más antiguos
My question is:
I have an array with values ranging from 0 to 200 something, and I need to find the average value for a set range of the data i.e. I need to find the average value for 0 to 1, the average value of the data for 1-2, and so on until it hits the end. I would like to save that information in a new matrix that I can look up later on.
Any help is appreciated.
2 comentarios
James Tursa
el 23 de Mzo. de 2016
What about the boundary points? E.g., if a value is exactly 1, do you want it to be part of the 0-1 average and also the 1-2 average? Or do you want these averages to be mutually exclusive?
KK
el 23 de Mzo. de 2016
Respuesta aceptada
Más respuestas (1)
James Tursa
el 23 de Mzo. de 2016
Editada: James Tursa
el 23 de Mzo. de 2016
Does something like this do what you want?
n = ceil(max(values));
x = bsxfun(@ge,values(:),0:n-1) & bsxfun(@le,values(:),1:n);
averages = sum(bsxfun(@times,values(:),x)) ./ sum(x);
averages(isnan(averages)) = 0;
1 comentario
KK
el 24 de Mzo. de 2016
Categorías
Más información sobre Logical 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!