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