From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: avoid the growing of a vector in a loop
Date: Wed, 25 Aug 2010 13:22:12 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <i53n7f$h19$>
References: <i53m2c$5pg$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 25 Aug 2010 18:25:52 +0000 (UTC)
Injection-Info:; posting-host="i5J7+R9zz18sq01MGwSHxQ";
	logging-data="17449"; mail-complaints-to="";	posting-account="U2FsdGVkX188XqDb8rjkUhGnJr9FN3Xa"
User-Agent: Thunderbird (Windows/20100228)
In-Reply-To: <HIDDEN>
Cancel-Lock: sha1:qpup+JxQsSJvwWJjzc/Lo7SzpEo=
Xref: comp.soft-sys.matlab:664977

Jose wrote:
> first loop
> 1. I would like to preallocate bxn to avoid the grown of the vector in 
> the loop.
> second loop
> 2. I would like to extract blocks of 41 points from the vector bxn

>  for i=1:nt-1
>  axn=data(maxindex(i)+2*ns:maxindex(i+1)-2*ns);

Nota Bene:  "i" is complex i in Matlab predefined; suggest using some 
other variable name to not overload it.  I use idx as a generic index 
variable as just a suggestion.


> 2. extracting blocks of 41 points of the vector bxn
>  for i=1:nt
>    rw=1+((length(bxn)-41)-1)*rand(1,1);
>    xn(i,:)=bxn(round(rw):round(rw)+40);
>  end

Simply generate an array of nt rn's, scale that number to the 
length(bxn) on the array and round it.  Then the selection is simply for 
each member of that vector:vector+40