找到你要的答案

Q:Matlab: how to plot density of events

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 !

我有一个只有1列包含日期的文件(格式dd/mm/yyyy)的一些事件,如下

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

我想绘制事件的概率密度:如何看待数据格式?

如果可能的话,我还想创建一个一维概率密度图:一行(从第一天到最后一天)根据事件的密度改变颜色。

Does anyone know how to do it? Thanks !

answer1: 回答1:

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.

这取决于你有多常发生可以用“月”命令,看到http://se.mathworks.com/help/finance/months.html。我想你也许不得不与空间变化的斜线。但你可以做些什么(我没有测试任何东西):

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

然后你有每月出现的次数。我猜会有一种类似的方法来计算每次发生的天数,然后对两者之间的天数做一些统计。的着色问题可以绘制一条线块的时间,然后指定一个颜色为RGB颜色代码,比如蓝色和红色的0.1倍0.2倍的分。所以17事件有颜色代码[ 0.2×1×0.1×7 ]。缩放当然依赖于预期出现的次数。

matlab  plot  probability-density