Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Dataset find and replace problem
Date: Fri, 6 Nov 2009 18:04:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 71
Message-ID: <hd1oei$3md$1@fred.mathworks.com>
References: <h6fb79$dpn$1@fred.mathworks.com> <h6fcpk$rm2$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257530642 3789 172.30.248.38 (6 Nov 2009 18:04:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 6 Nov 2009 18:04:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2080744
Xref: news.mathworks.com comp.soft-sys.matlab:583069


"us " <us@neurol.unizh.ch> wrote in message <h6fcpk$rm2$1@fred.mathworks.com>...
> "Bruce Ferguson" <bferguson1@penson.com> wrote in message <h6fb79$dpn$1@fred.mathworks.com>...
> > I have a dataset array named "sortBA" with three columns and lots of rows (500K+).
> > 
> > I have shown the first twenty rows below:
> > 
> > disp(sortBA(1:20,{'timemilli','cmeB','cmeA'}))
> > 
> >     timemilli        cmeB      cmeA  
> >     1247146199971    1.3986    1.3989
> >     1247146199981         0         0
> >     1247146200001         0         0
> >     1247146200043         0         0
> >     1247146200044         0         0
> >     1247146200049         0         0
> >     1247146200056         0         0
> >     1247146200061         0         0
> >     1247146200081         0         0
> >     1247146200091         0         0
> >     1247146200145    1.3986    1.3989
> >     1247146200188         0         0
> >     1247146200215         0         0
> >     1247146200229         0         0
> >     1247146200250    1.3986    1.3989
> >     1247146200266    1.3987     1.399
> >     1247146200290         0         0
> >     1247146200299    1.3987    1.3989
> >     1247146200302         0         0
> >     1247146200303    1.3986     1.399
> > 
> > I need to do a form of "sample and hold" in engineering terms. I want to see if a cell of column "cmeB" or a cell of column  "cmeA" contains a zero.  If it contains a zero I want to replace the zero with the most recent previous nonzero cells value in that column and continue down the rows until I reach the length of the variable "sortBA".  
> > 
> > I have tried everything I can find to do this without luck.
> > 
> > Any help will be greatly appreciated....
> 
> one of the many solutions is outlined below
> 
> % the data
>      m=[
>           1.2
>           0
>           2.4
>           0
>           0
>           3.6
>           0
>           4.8
>      ];
> % the engine
>      ms=cumsum(m~=0);
>      md=m(m~=0);
>      r=md(ms);
> % the result
>      disp(r);
> %{
>           1.2
>           1.2
>           2.4
>           2.4
>           2.4
>           3.6
>           3.6
>           4.8
> %}
> 
> us



I think your code( which is really good by the way ) works only on positive data ? is that right ? we should adapt it a bit vectors uncluding negative data ?