I have ploted two diff histograms in the same graph. I want to plot a smooth line above the histogram, kind of the density function. If I use the basic fitting tool in matlab, I can do it but only for one histogram and not both at the same time. I want to compare both in the same graph and actually hiding the histograms.
Any coments?
thanks
> I have ploted two diff histograms in the same graph. I want to plot a smooth line above the histogram, kind of the density function. If I use the basic fitting tool in matlab, I can do it but only for one histogram and not both at the same time. I want to compare both in the same graph and actually hiding the histograms.
If you have access to the Statistics Toolbox, the KSDENSITY function may be of use. Since a histogram is not normalized in the same way as a probability density, you'l have to either normalize the histogram bars or the output of KSDENSITY.
---------------------------------------------------
Rogelio:
Why can't you just plot the histograms using the bar() command and
then do the curve fits, then turn "hold on" and plot the two fitted
curves with the plot() command? You might have to interpolate some
values in between the bar locations so that you get a smooth curve,
rather than a piecewise linear plotting, but I think it should work.
Regards,
ImageAnalyst
Dear Rogelio,
As an extension to what ImageAnalyst has mentioned, I am kind of sure
this will help you. You really dont need a fitting tool.
Consider this:
say your data is given by vector - data
Choose number of bins: say 100,
numbins = 100;
n = length(data);
binwidth = range(data)/numbins;
edg= min(data):binwidth:max(data);
[count, bin] = histc(data, edg);
h = bar(edg, count./(n*binwidth), 'histc');
set(h, 'facecolor', [0.8 0.8 1]); % change the color of the bins
set(h, 'edgecolor', [0.8 0.8 1]);
p = count./(n*binwidth);
save p;
hold on;
plot(p,edg); % plot(p,edg) is the smooth curve representing the
probability density function you are looking for.
hold off;
Ofcourse you can then superimpose as many curves of other data on top
of it using hold, no problem. Hope this helps.
All the best,
adshak