Plot mean and standard deviation of data at particular intervals
4 views (last 30 days)
Show older comments
I have a large amount of data which is not evenly spread. I wish to bin the data so that it is intervals of 0.1 and then for each of the intervals I wish to find the mean and the standard deviation. I then wish to plot this. How would I go about doing this? Thank you
1 Comment
Marc
on 11 Nov 2013
There are many different ways to approach this. Try 'hist' first off and take a look at the statistics toolbox if you have it.
You could use logical indexing to grab the various intervals. You could use 'find' which often warns you that logical indexing is better, but if you are new to this, then I would suggest looking at the documentation for 'find'.
The nice thing with Matlab is that mean and std work on columns or rows, so with a little thought, it's easy to automate this task.
Give it a little bit more thought and show us some code that is hanging you up. Otherwise, your question is simply to open ended.
Answers (1)
Walter Roberson
on 11 Nov 2013
interval = 0.1;
datamin = min(YourData);
binidx = 1 + floor((YourData - datamin) ./ interval);
binmeans = accumarray(binidx(:), YourData(:), [], @mean);
binstd = accumarray(binidx(:), YourData(:), [], @std);
bincent = datamin + (interval * 3/2) * (0:length(binmeans)-1);
subplot(2,2,1);
plot(bincent, binmeans, 'b');
ytitle('means');
subplot(2,2,2);
plot(bincent, binstd, 'r');
ytitle('standard deviations');
See Also
Categories
Find more on Earth, Ocean, and Atmospheric Sciences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!