Path: news.mathworks.com!not-for-mail
From: "Theodor Zouk" <rebet4@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing different parts of the same array
Date: Tue, 7 Oct 2008 06:17:03 +0000 (UTC)
Organization: Univ of Umea
Lines: 38
Message-ID: <gceusv$c9v$1@fred.mathworks.com>
References: <gcd9os$6vt$1@fred.mathworks.com> <gcdelq$5he$1@fred.mathworks.com> <gcdh8a$3lm$1@fred.mathworks.com> <gce0dt$9j6$1@fred.mathworks.com>
Reply-To: "Theodor Zouk" <rebet4@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1223360223 12607 172.30.248.35 (7 Oct 2008 06:17:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 7 Oct 2008 06:17:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1540208
Xref: news.mathworks.com comp.soft-sys.matlab:493959


"Jos " <DELjos@jasenDEL.nl> wrote in message <gce0dt$9j6$1@fred.mathworks.com>...
> "Theodor Zouk" <rebet4@hotmail.com> wrote in message <gcdh8a$3lm$1@fred.mathworks.com>...
> > "Adam " <not.real@email.com> wrote in message <gcdelq$5he$1@fred.mathworks.com>...
> > > "Theodor Zouk" <rebet4@hotmail.com> wrote 
> > > 
> > > > I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...
> > > 
> > > can you reshape to 4096xN and work on each column?
> > > 
> > > ~Adam
> > 
> > No i can't reshape... because i have a vector.
> 
> Wrong!
> 
> > My problem is more like: how can i access each element in a part of an vector then store those values (or at best be able to calculate things in parallell) and then continuing to read elements in the same vector from were i stopped reading the first time... 
> > 
> > I want to vectorize this for example:
> > 
> > vec=(1:10);
> > mat= zeros(5,2);
> > k=1;
> > 
> > for i=1:2:10
> >     mat(k,:)= vec(i:i+1);
> >     k=k+1;
> > end
> 
> vec = 1:10 ;
> mat = reshape(vec,2,[]).'
> 
> Jos


It works.
thank you Jos

/TEO