help-octave
[Top][All Lists]
Advanced

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

Re: subarray(x, d, k) for picking all k-th elements of d-th dimension of


From: Francesco Potorti`
Subject: Re: subarray(x, d, k) for picking all k-th elements of d-th dimension of x ?
Date: Fri, 24 Apr 2009 15:04:42 +0200

>> Very often I would need a function subarray(x, d, k) that picks, for integers
>> d and k, from an array x all k-th elements at dimension d:
>>
>> y = subarray(x, d, k)   <=>   y = x(:,...,:,k,:,...,:)
>>
>> where k is at position d.

>idx = {':'}(ones (1, max (ndims (x), d))); idx{d} = k; % or anything
>y = x(idx{:});

I used:

  allidx = num2cell(repmat(":",1,ndim));
  subidx = allidx; subidx{d} = k;
  sub = b(subidx{:});

And yes, technically this is all documented (I learnt it from the docs)
but it is very terse and often cryptic.  Yes, more examples would be
very useful.  I have plans for writing some, but I have too many plans...

-- 
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]