# Q：MATLAB如何情节密度的事件

I have a file of just 1 column containing the dates (in the format dd/mm/yyyy) of some events, as follows

``````13/01/2003
07/01/2003
23/01/2003
25/01/2003
...
27/12/2014
``````

I would like to plot the probability density of the events: how to treat the data format?

If it is possible, I would like also to create a 1D probability density plot: a line (from the first day to the last day) that changes color according to the density of events.

Does anyone know how to do it? Thanks !

``````13/01/2003
07/01/2003
23/01/2003
25/01/2003
...
27/12/2014
``````

Does anyone know how to do it? Thanks !

Depending on how often you have an occurrence you can use the "months" command, see http://se.mathworks.com/help/finance/months.html . I think that maybe you have to change the slashes with spaces. But then you can do something like (I haven't tested anything):

``````a = date(1);
dens = 1;
for i = 2:length(date)
%Same month
if weeks(a,date(i)) == 0
dens(end) = dens(end)+1;
else
a = date(i);
dens = [dens, 1];
end
end
``````

then you have the number of occurrences per month. I guess there will be a similar method to count the number of days between each occurrence and then make some statistics on the number of days in between. For the coloring problem you can plot one line piece at a time and then specify a color as its RGB color code where the for instance the blue is the ones times 0.1 and the red is 0.2 times the tenths. So 17 occurrences has the color code [0.2*1 0 0.1*7]. The scaling does of course depend on the number of expected occurrences.

``````a = date(1);
dens = 1;
for i = 2:length(date)
%Same month
if weeks(a,date(i)) == 0
dens(end) = dens(end)+1;
else
a = date(i);
dens = [dens, 1];
end
end
``````

matlab  plot  probability-density