Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!u4g2000pbu.googlegroups.com!not-for-mail
From: Olivia Wright <owright2@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Sum hourly precip data to storm events
Date: Thu, 26 Apr 2012 18:24:02 -0700 (PDT)
Organization: http://groups.google.com
Lines: 44
Message-ID: <cfd517e8-6edb-4852-8062-cb781fb83848@u4g2000pbu.googlegroups.com>
References: <jn7jtt$hf8$1@newscl01ah.mathworks.com> <jnbspg$2dp$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: 128.95.45.173
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1335489842 3730 127.0.0.1 (27 Apr 2012 01:24:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 27 Apr 2012 01:24:02 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: u4g2000pbu.googlegroups.com; posting-host=128.95.45.173; posting-account=fKy3JgoAAADCsTvh62IERrL-xI34klP_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0,gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:766079

On Apr 26, 9:23 am, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Olivia " <owrig...@gmail.com> wrote in message <jn7jtt$hf...@newscl01ah.mathworks.com>...
> > Hi all! I have hourly precipitation data that I want to sum into individual storm events. If there are 24 hours with no rainfall (value 0), the storm ends and I would like the code to start adding the values of a new storm. The resulting output will be the precipitation depth of each storm event. Anyone have any ideas how I can do this in matlab? Thank you!
>
> - - - - - - - - - - -
>   How about a simple for-loop solution?  It's easier to code than a vectorized method.  (Moreover, I am guessing it will be faster in spite of the number of lines.)
>
>   Let x be a vector giving the hourly precipitation.
>
>  y = zeros(size(x));
>  f = false;
>  iy = 0;
>  for ix = 1:length(x)
>    if x(ix) ~= 0
>      c = 0;
>      if ~f
>        f = true;
>        iy = iy + 1;
>      end
>      y(iy) = y(iy) + x(ix);
>    else
>      if f
>        c = c + 1;
>        if c >= 24
>          f = false;
>        end
>      end
>    end
>  end
>  y = y(1:iy);
>
> Then y is a vector giving total precipitation for each storm.
>
> Roger Stafford

That worked great! Thank you Roger!