MATLAB: How to use a loop for an array

#array #loop #help

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.

Best Answer

If you have the Statistics and Machine Learning Toolbox, you can use grpstats(). It's a single line of code:
% Create sample data
r = 200 * rand(100000, 1);
% Now find means in every integer range.
means = grpstats(r, floor(r))
Related Question