Using MATLAB to find strings of numbers in nominal data
I have a file of nominal data containing year, month, day, and exceedence.
If a day is an exceedence, it is assigned a 1. If it is not an exceedence,
it is assigned a 0. I want to find strings of days that are characterized
by a 1. The strings have to be a minimum of length 2. Also, since 3 days
of 1s also contains a 2-day string of 1s, there has to be at least one day
separating a string of 1s for the strings to be separate. In other words,
a 2-day string would have to have at least one day between it and another
string of 1s for it to be considered a 2-day string. This same rule would
have to follow for all strings of any length. I'm not sure how to set this
up...Here's a look at the code I have so far:
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);
I don't have to worry about leap years because I'm only using two months
(July and August). At the end of the day, I want a file containing the
year for the first column, and the total number of strings of 1s of a
given length for the subsequent columns. In other words, I want to know
how many times there were 2-day strings of ones, 3-day strings of ones,
4-day strings of ones, and so forth in a given year. I hope this makes
sense!
Thanks,
Zach
No comments:
Post a Comment