0

我有一个包含年、月、日和超出的标称数据文件。如果一天超出,则分配 1。如果不是超出,则分配 0。我想找到以 1 为特征的日期字符串。字符串的长度必须至少为 2 . 另外,由于 3 天的 1 还包含 2 天的 1 字符串,因此必须至少有一天分隔 1 字符串才能将字符串分开。换句话说,一个 2 天的字符串与另一个 1 字符串之间必须至少有一天,才能被视为 2 天的字符串。对于任何长度的所有字符串,都必须遵循同样的规则。我不知道如何设置它......这是我到目前为止的代码:

load file_name.txt
year=file_name(:,1);
month=file_name(:,2);
day=file_name(:,3);
exceedence=file_name(:,4);

for i=1:61
    yr=i+1950;
    for j=7:8
        for k=1:31
            [yr j k];
            ga=find(year==yr&month==j&day==k&exceedence);
            x=exceedence(ga);

我不必担心闰年,因为我只使用两个月(七月和八月)。在一天结束时,我想要一个文件,其中包含第一列的年份,以及后续列的给定长度的 1 字符串的总数。换句话说,我想知道在给定年份中有多少次 2 天的字符串、3 天的字符串、4 天的字符串等等。我希望这是有道理的!

谢谢,

扎克

4

1 回答 1

0

It is not obvious how this code gets your sequences of ones and zeros to start with. I am assuming that is not the hard part, so once you have that sequence, here is what I would do.

if x is your sequence, first prepend and append zeros

x = [0,x,0]

Then take the diff to find the transitions

transitions = diff(x)
upTransitions = find(transitions > 0)
downTransitions = find(transitions < 0)

nDays = downTransitions - upTransitions + 1;

You can then take a histogram

hist(nDays)

If you want to customize the histogram bins, just do help hist to see the options.

于 2013-08-28T23:51:49.383 回答