Thread Subject: Dataset find and replace problem

Subject: Dataset find and replace problem

From: Bruce Ferguson

Date: 18 Aug, 2009 22:50:17

Message: 1 of 3

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....

Subject: Dataset find and replace problem

From: us

Date: 18 Aug, 2009 23:17:08

Message: 2 of 3

"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

Subject: Dataset find and replace problem

From: setijioon junam

Date: 6 Nov, 2009 18:04:02

Message: 3 of 3

"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 ?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
cumsum us 18 Aug, 2009 19:19:20
code us 18 Aug, 2009 19:19:20
linear indexing us 18 Aug, 2009 19:19:20
logical indexing us 18 Aug, 2009 19:19:20
dataset Bruce Ferguson 18 Aug, 2009 18:54:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com