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 o


From: Jaroslav Hajek
Subject: Re: subarray(x, d, k) for picking all k-th elements of d-th dimension of x ?
Date: Fri, 24 Apr 2009 11:47:46 +0200

On Fri, Apr 24, 2009 at 11:07 AM, G.. <address@hidden> wrote:
>
> 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.
>
> Is there any such thing?
>
> G.
>

Well, no, but you can write it:

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

cheers

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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