-1

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

user2877623
  • 35
  • 1
  • 7

1 Answers1

3

This sounds like a strange thing to do.

This ought to work, depending on what you data is

data=sort(data);
numelements=histc(data,min(data):0.1:max(data));
M=zeros(size(numelements));SD=M;
M(1)=mean(data(1:numelements(1)));
SD(1)=std(data(1:numelements(1)));
ind=cumsum(numelements);
for i=2:length(numelements)
    M(i)=mean(data(ind(i-1):ind(i)));
    SD(i)=std(data(ind(i-1):ind(i)));
end

Then errorbar(min(data):0.1:max(data),M,SD,'x') should give you error bars.

David
  • 8,449
  • 1
  • 22
  • 32
  • 1
    If it would be more natural to specify bin edges rather than bin centers, use `histc` rather than `hist`. For this question I probably would have used `histc` but I don't think it's necessarily well-specified. – tmpearce Nov 11 '13 at 03:18