I'm working on my biometrics course, and I have to plot a pdf (I think it means probability density / distribution function). Here is a sample pdf graph : Introduction to Biometrics page 5 , figure 2.a

I have the data for genuine and impostor scores, in MATLAB. So I have two vectors, which contain hundreds of data (values of which are between 0 and 1). But I have no idea how to pdf-plot them.

I tried probplot(data) function of MATLAB, but it gaves an increasing function, whereas I was expecting a bell-curve shape. See the image : probplot

I also see that there is a pdf function of MATLAB, but it asks you to use which kind of pdf. Maybe normal distribution is the one for me, but I'm confused because it also asks for the mean and st.dev. values. Shouldn't the function compute these for me?

In the end, how can I get a PDF plot like in the link ?

Thanks for any help !


ksdensity plot for the genuine scores: enter image description here

Edit 2:

Output for normpdf(scores , mean(scores) , std(scores)); : enter image description here

Edit 3:

This is the actual graph I'm trying to achieve : (x-axis values are not important) enter image description here

Edit 4:

output of this : (an un-readable version of http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/155832 this answer)

vector_to_pdfplot = genuine_scores; 
plot(min(vector_to_pdfplot) : ((max(vector_to_pdfplot) - min(vector_to_pdfplot))/1000) : max(vector_to_pdfplot) , normpdf(min(vector_to_pdfplot) : ((max(vector_to_pdfplot) - min(vector_to_pdfplot))/1000) : max(vector_to_pdfplot) , mean(vector_to_pdfplot) , std(vector_to_pdfplot) ));

enter image description here

  • $\begingroup$ The probplot function compares your data with the normal cdf (hence the increasing function with range [0,1]). To plot the pdf, you may find this of use: mathworks.co.uk/matlabcentral/newsreader/view_thread/155832 $\endgroup$ Mar 8, 2014 at 13:05
  • $\begingroup$ @GeorgeTomlinson thanks! But I don't get this : why do we compute a mean value ? I just need the probability for the value of a variable selected from the set. There is no "mean" value I'm interested in. I hope I could explain my problem. $\endgroup$
    – jeff
    Mar 8, 2014 at 13:40
  • $\begingroup$ I don't know why it takes the mean as an argument, but I don't see that it's a problem to compute this. This is utter speculation, but maybe supplying the mean as an argument means that it's possible not only to plot a pdf of a given set of values in the way you want to, but also to plot a pdf based on a sample of values from a population whose mean is known. $\endgroup$ Mar 8, 2014 at 14:09
  • $\begingroup$ No it is not. Ok let me paste the output of normpdf. $\endgroup$
    – jeff
    Mar 8, 2014 at 14:10
  • $\begingroup$ Are you using the data values as the first argument? I don't think this is what you're supposed to do. See the link in my first comment or my answer for details. $\endgroup$ Mar 8, 2014 at 14:20

2 Answers 2


Try hist(data) to get a histogram.

You can also try

[f,xi] = ksdensity(data)

to get a smoothed histogram.

You can restrict the domain (since the default is the real number line):

support = (0:.01:1)'
[f] = ksdensity(data,support)
  • $\begingroup$ Thanks ! +1. This sure prints a much prettier graph. But I'm confused with one thing. It shows a positive probability of data being > 1. Whereas the data is normalized between 0 and 1. $\endgroup$
    – jeff
    Mar 8, 2014 at 13:08
  • $\begingroup$ Can you add the graph? $\endgroup$
    – dimitriy
    Mar 8, 2014 at 13:15
  • $\begingroup$ The height does not tell you the probability. The area under the pdf does. This means the height can exceed one. If you're getting positive density for x above one, you can use the support option to restrict it to [0,1]. $\endgroup$
    – dimitriy
    Mar 8, 2014 at 13:24
  • $\begingroup$ I attached the ksdensity output. It sure makes sense, except being greater than 1. $\endgroup$
    – jeff
    Mar 8, 2014 at 13:37
  • $\begingroup$ I added the code showing how to restrict the domain. $\endgroup$
    – dimitriy
    Mar 10, 2014 at 17:22

I suggest adapting this code I've taken from the link I gave in my first comment.

>> A = rand(700,1);
>> MAX = max(A);
>> STD = std(A);
>> MAX = max(A);
>> MIN = min(A);
>> STEP = (MAX - MIN) / 1000;
>> PDF = normpdf(MIN:STEP:MAX, M, S);
>> plot(MIN:STEP:MAX, PDF);

In your case the distribution isn't random, but I imagine you can apply the principles used here.

In particular, the first argument should be a combination of the maximum, minimun and a step size which depends upon the maximum, minimum and one other number (1000 in the example). I'm afraid I can't offer any help on how to choose the number in your case.

EDIT: maybe just modifying your code so that it's in this format will solve the problem:

x = -100:0.1:100;

What's the difference? The difference is that defining your x values beforehand alters MATLAB's scaling:

quoting the answer I posted in the comments:

When you call plot with ONE argument, it plots those numbers on the y axis, using the index numbers of those values for the x axis. If you wanted the x axis scaled properly, you had to provide them in the first place. Thus...

x = -100:0.1:100;

produces very different results to


contrary to what one might expect.

  • $\begingroup$ Thanks! +1, but again something strange. It does not go back to zero. Posting the output of this to the answer. $\endgroup$
    – jeff
    Mar 8, 2014 at 14:26
  • $\begingroup$ No problems. Thanks for the +1. Possibly just a scaling issue: you may need to find out how to force MATLAB to set the minimum x label to 0. However, it may help to try using a number other than 1000 (in fact, it may be necessary to do so): perhaps a number 30% larger than the number of data values, although this is a guess, based on the fact that 1000 is comparably larger than 700 (I know it's not 30% larger). This link may also help, although it may not make any difference, but I thought I'd post it in case: stackoverflow.com/questions/3820240/… $\endgroup$ Mar 8, 2014 at 14:38
  • $\begingroup$ Oh, sorry, you mean at the right hand end. It could be to do with the 1000. It could be the choice of mean and variance. It could be something else. I don't know I'm afraid. If you can adjust the x axis so that it ranges from 0 to 1, the plot may (or may not) look better, but it still may not be perfect. The accepted answer on this link does imply that incorrect scaling of the x axis label values can produce weird results, so possibly you need to give some thought to how to find the best x axis label values : stackoverflow.com/questions/3820240/… $\endgroup$ Mar 8, 2014 at 14:53
  • $\begingroup$ Please see the edit to my answer: it may solve your problem. Another possible solution is that the mean and s.d. you supply need to be different. We still don't know whether using the sample mean and s.d. is correct and if not, what they should be instead. I'm afraid I don't know the answers to these questions at present. $\endgroup$ Mar 8, 2014 at 15:10
  • $\begingroup$ I think normpdf is plotting the actual normal pdf corresponding to the mean and standard deviation you supply for the range you supply, which isn't what you want. You want to plot the possible data values against the probability of it being less than a given value, so I don't think normpdf is what you need, in fact. $\endgroup$ Mar 8, 2014 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .