0

I have a 1x4225 vector that its elements are between 0 and 1 and I want to plot their probability density function in matlab. In the case of ksdensity() the problem is that the probability sometimes gets more than 1. I also tried the code below to do that:

A= [1x4225];           
xRange = 0:1;                
N = hist(A,xRange);        
plot(xRange,N./numel(A))

But because of huge number of my data it made an ambiguous plot that consists of some vertical lines and is useless for me. So is there any way to solve this problem or any other way to do this in matlab that shows each element as a separate point in pdf plot ?

Saba
  • 61
  • 2
  • 9
  • Are you sure you want `xRange = 0:1;` think you want more than two points so try something more like `xRange = 0:0.1:1;` – Dan Oct 25 '13 at 06:58
  • That's what my answer says. ;) – chappjc Oct 25 '13 at 06:59
  • Just wanted to clarify that a density for a continuous r.v. (PDF) can be greater than one since it is a derivative of a probability (or intensity), not a probability itself. The cumulative distribution (CDF) is itself a probability and therefore must be on [0, 1]. – SecretAgentMan Oct 21 '18 at 16:19

1 Answers1

0

When you do xRange = 0:1; you get a 2-element vector [0 1]. That is probably not what you want. Specify a step like:

xRange = 0:0.01:1;

Plotting each element as a point is accomplished in MATLAB with the line specifier argument, like plot(xRange,N./numel(A),'*'). However, for a histogram with only a small number of bins, you might be better off with bar(...). If you go with a finer step, then plotting might be better.

chappjc
  • 30,359
  • 6
  • 75
  • 132