help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: vectorise matrix slice extraction


From: Francesco Potorti`
Subject: Re: vectorise matrix slice extraction
Date: Fri, 27 Feb 2009 16:58:08 +0100

>> Is there a way to efficiently remove the for loop in this assignment?
>>
>>   for jj = length(pple):-1:1
>>     llk(:,:,:,jj) = ll(:,:,:,pple(jj),tple(jj));
>>   endfor
>
>Maybe try
>
>       s = size(ll);
>       s1 = 1:s(1); # etc.
>       llk( s1,s2,s3, 1:numel(pple) ) =
>               reshape( ll(s1,s2,s3, pple, tple), [s(1:3), numel(pple)] );

This would be equivalent to 
  llk = ll(:,:,:,pple,tple);

but it does not work.  Take this as an example:

octave> a=reshape(1:9,3,3)
a =

   1   4   7
   2   5   8
   3   6   9

octave> ia=1:2;ib=2:3;

What I want is this:

octave> [a(ia(1),ib(1)), a(ia(2),ib(2))]
ans =

   4   8

Not this:

octave> a(ia,ib)
ans =

   4   7
   5   8

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]