From help-octave-request at bevo dot che dot wisc dot edu Wed Jan 29 10:34:31 2003 Subject: Re: Combining histograms and function plots From: Miquel Cabanas To: Toke Reichstein Cc: help-octave at bevo dot che dot wisc dot edu Date: Wed, 29 Jan 2003 17:33:16 +0100 hi, On Wed, Jan 29, 2003 at 03:45:47PM +0100, Toke Reichstein wrote: > > Q1: How do I plot a normal distribution function with the mean and > standard deviation of my data in Octave? use the function "normal_pdf()". I'm not sure it's part of the standard distribution, if you fail to find it go and download it from the sourceforge repository http://octave.sourceforge.net > Q2: How do I plot it ontop of my histogram plots? see the example below. # Since i've no real data i'll fake some normally distributed # random one (matrix size 100*100) data = randn (100); # you can check it with. Note that i use data(:) so that it is # treated as a one-row vector instead of as a matrix. plot (data(:)) # now let's calculate some statistics. Again, i use data(:) to # treat it as a single-row vector. Try "mean (data)" to see the # difference. mean_data = mean (data(:)); var_data = var (data(:)); # now hist() can be used to plot the histogram. Hist() has several # options, check them in the online help. The way it's written # below will make an histogram of data(:), with bins from -5 to 5 # and as many bins as given by the increment: 101 bins, and it will # be normalized to area "1" (last argument). hist (data(:), [-5:.1:5], 1) # now hold the plot so that the next plot doesn't overwrite it hold on # it's time to use normal_pdf to calculate our distribution probability. # For this i give the x-values, the mean value of the distribution, # and the variance data_pdf = normal_pdf ([-5:.1:5], mean_data, var_data); # then i normalize data_pdf to area one data_pdf = data_pdf ./ sum (data_pdf) ; # now I can plot the distribution stored in data_pdf plot ([-5:.1:5], data_pdf) Also check bar() if you plan to manipulate your bins. Miquel -- Miquel E Cabanas ------------------------------------------------------ SeRMN, Universitat Autonoma de Barcelona (Miquel dot Cabanas at uab dot es) MRUI Software Manager (mrui-mgr at mrui dot uab dot es) ------------------------------------------o-oo--ooo---ooo--oo-o-------- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------