Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Dataset find and replace problem
Date: Tue, 18 Aug 2009 23:17:08 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 66
Message-ID: <h6fcpk$rm2$1@fred.mathworks.com>
References: <h6fb79$dpn$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 1250637428 28354 172.30.248.38 (18 Aug 2009 23:17:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 18 Aug 2009 23:17:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:564319


"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