[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing rows/columns from a matrix
From: |
Søren Hauberg |
Subject: |
Re: Removing rows/columns from a matrix |
Date: |
Fri, 21 Mar 2008 16:39:27 +0100 |
fre, 21 03 2008 kl. 08:15 -0700, skrev Ben Abbott:
> This will work in Octave (does not work in Matlab).
>
> A = rand (5, 5, 5);
> b = {2:5 1:5 2:5};
> A = A(b{:});
>
> The only trick is creating the cell for b.
Matlab doesn't matter, so I've the following:
idx = cell(1, ndims(A));
for k = 1:ndims(A)
idx{k} = (b(k)+1):size(A,k);
endfor
A = A(idx{:});
which seems to work.
Thanks,
Søren