Thread Subject: Zeros some value in array

Subject: Zeros some value in array

From: Jaroslav

Date: 25 Aug, 2009 13:01:05

Message: 1 of 8

Hi,

how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
For example, I have array of 10 numbers A=[1:10]
and result would be look like 0 0 0 4 5 0 0 0 9 10

Thanks

Subject: Zeros some value in array

From: Andy

Date: 25 Aug, 2009 13:27:02

Message: 2 of 8

"Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h70nah$rkk$1@fred.mathworks.com>...
> Hi,
>
> how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
> For example, I have array of 10 numbers A=[1:10]
> and result would be look like 0 0 0 4 5 0 0 0 9 10
>
> Thanks

A=1:10;
idx=[1:3 6:8]; % indexes to make zero
A(idx)=0;

Subject: Zeros some value in array

From: Jaroslav

Date: 25 Aug, 2009 19:42:19

Message: 3 of 8

"Andy " <theorigamist@gmail.com> wrote in message <h70or6$ak0$1@fred.mathworks.com>...
> "Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h70nah$rkk$1@fred.mathworks.com>...
> > Hi,
> >
> > how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
> > For example, I have array of 10 numbers A=[1:10]
> > and result would be look like 0 0 0 4 5 0 0 0 9 10
> >
> > Thanks
>
> A=1:10;
> idx=[1:3 6:8]; % indexes to make zero
> A(idx)=0;

Thanks Andy,

but in fact, I will have about 95000 samples. So this way is not what I looking for..

But thank you..

Subject: Zeros some value in array

From: Andy

Date: 25 Aug, 2009 20:27:07

Message: 4 of 8

"Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h71eqr$6rf$1@fred.mathworks.com>...
> "Andy " <theorigamist@gmail.com> wrote in message <h70or6$ak0$1@fred.mathworks.com>...
> > "Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h70nah$rkk$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
> > > For example, I have array of 10 numbers A=[1:10]
> > > and result would be look like 0 0 0 4 5 0 0 0 9 10
> > >
> > > Thanks
> >
> > A=1:10;
> > idx=[1:3 6:8]; % indexes to make zero
> > A(idx)=0;
>
> Thanks Andy,
>
> but in fact, I will have about 95000 samples. So this way is not what I looking for..
>
> But thank you..

% This approach still works with 95000 samples. You just want to create idx in
% some way other than explicitly choosing which indexes to remove.

% Example: create a vector of random data and remove all values below 0.3:

A=rand(100000,1);
idx=find(A<0.3);
A(idx)=0;

% If you'd like more help doing this, what are your criteria for determining which
% indexes you want to replace with 0?

Subject: Zeros some value in array

From: Jaroslav

Date: 26 Aug, 2009 07:15:08

Message: 5 of 8

"Andy " <theorigamist@gmail.com> wrote in message <h71her$1c6$1@fred.mathworks.com>...
> "Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h71eqr$6rf$1@fred.mathworks.com>...
> > "Andy " <theorigamist@gmail.com> wrote in message <h70or6$ak0$1@fred.mathworks.com>...
> > > "Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h70nah$rkk$1@fred.mathworks.com>...
> > > > Hi,
> > > >
> > > > how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
> > > > For example, I have array of 10 numbers A=[1:10]
> > > > and result would be look like 0 0 0 4 5 0 0 0 9 10
> > > >
> > > > Thanks
> > >
> > > A=1:10;
> > > idx=[1:3 6:8]; % indexes to make zero
> > > A(idx)=0;
> >
> > Thanks Andy,
> >
> > but in fact, I will have about 95000 samples. So this way is not what I looking for..
> >
> > But thank you..
>
> % This approach still works with 95000 samples. You just want to create idx in
> % some way other than explicitly choosing which indexes to remove.
>
> % Example: create a vector of random data and remove all values below 0.3:
>
> A=rand(100000,1);
> idx=find(A<0.3);
> A(idx)=0;
>
> % If you'd like more help doing this, what are your criteria for determining which
> % indexes you want to replace with 0?


It does not matter, what indexes will be replaced with 0. But the number of 0 must be always same and this interval of zeros should be repeated randomly or periodically up to end of samples (in array).

Subject: Zeros some value in array

From: Lorenzo Guerrasio

Date: 26 Aug, 2009 08:47:03

Message: 6 of 8

I'm not sure if I got what you want. take a look, maybe it helps. It's not the best solution, probably.

my_seq=[0 0 1 1 0];%here you put the sequence of zero you like
my_vect=rand(1,54353);
Nrep=floor(length(my_vect)/length(my_seq));
my_mask=repmat(my_seq,1,Nrep);
my_mask=[my_mask,my_seq(1:(length(my_vect)-length(my_mask)))];
new_vect=my_vect.*my_mask;



"Jaroslav " <jaroslav.hrebicek@seznam.cz> wrote in message <h70nah$rkk$1@fred.mathworks.com>...
> Hi,
>
> how could I zeros some numbers in array? I need replace for example first three numbers by zeros, then keep original 2 numbers and then again replace next three numbers by zero etc.
> For example, I have array of 10 numbers A=[1:10]
> and result would be look like 0 0 0 4 5 0 0 0 9 10
>
> Thanks

Subject: Zeros some value in array

From: us

Date: 26 Aug, 2009 08:50:18

Message: 7 of 8

"Jaroslav "
> It does not matter, what indexes will be replaced with 0. But the number of 0 must be always same and this interval of zeros should be repeated randomly or periodically up to end of samples (in array)...

one of the solutions
- for the rand case...

     n=4; % <- #data to replace with zeros
     v=1:10;
     ix=randperm(numel(v));
     v(ix(1:n))=0;

us

Subject: Zeros some value in array

From: us

Date: 26 Aug, 2009 09:03:19

Message: 8 of 8

"us " <us@neurol.unizh.ch> wrote in message <h72t0a$9je$1@fred.mathworks.com>...
> "Jaroslav "
> > It does not matter, what indexes will be replaced with 0. But the number of 0 must be always same and this interval of zeros should be repeated randomly or periodically up to end of samples (in array)...
>
> one of the solutions
> - for the rand case...
>
> n=4; % <- #data to replace with zeros
> v=1:10;
> ix=randperm(numel(v));
> v(ix(1:n))=0;
>
> us

unfortunately, the second part got lost in the copy/paste process...

one of the solutions
- for the rand case...
...
- for the periodic case

     v=1:16;
     tmpl=[0,0,1,1]; % <- min block of zeros/data with numel(v) = N x numel(tmpl)!
     r=reshape(bsxfun(@times,reshape(v,numel(tmpl),[]).',tmpl).',1,[]);
     disp([v;r]);
%{
          1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
          0 0 3 4 0 0 7 8 0 0 11 12 0 0 15 16
%}

us

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
numel us 26 Aug, 2009 05:04:03
bxsfun us 26 Aug, 2009 05:04:03
reshape us 26 Aug, 2009 05:04:03
code us 26 Aug, 2009 04:54:05
randperm us 26 Aug, 2009 04:54:05
linear indexing us 26 Aug, 2009 04:54:05
zeros values in... Sprinceana 26 Aug, 2009 03:24:49
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