selecting 'first' element/vector/matrix of an arbitrary n-dim array
Nicholas Jankowski <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.general |
|---|---|
| Message-ID | <CABNpfR9-7p_y0d7rW-HdFXMPe5J1kXcyE+s_bczr041a2Jpd5A@mail.gmail.com> |
i'm sure there's a compact, efficient way to do this, but it's eluding me
and my google-fu is failing:
give a n-dimensional matrix A (n unknown apriori), and a user specified
dimension to operate on, return the first 'part' of the array for that
dimension, preserving shape:
e.g, for a 3D array, dim 2:
B = A(:,1,:)
for dim 3:
B = A(:,1,:)
for a 4D array, dim 2:
B = A(:,1,:,:)
for dim 4:
B = A(:,:,:,1)
etc.
what's an efficient way to extract that subarray for any number of
dimensions? i assume I could do something clever directly with subsasgn and
expanding a cell array of some number of ':' with {:}, but i'm sure I'm
missing something cleaner, no?
(does not need to be matlab compatible)