Plot mean and standard deviation of data at particular intervals
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Marc
2013년 11월 11일
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.
답변 (1개)
Walter Roberson
2013년 11월 11일
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');
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!