[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing rows/columns from a matrix
From: |
Ben Abbott |
Subject: |
Re: Removing rows/columns from a matrix |
Date: |
Fri, 21 Mar 2008 08:15:09 -0700 |
On Friday, March 21, 2008, at 11:00AM, "Søren Hauberg" <address@hidden> wrote:
>Hi,
> Let's say I have a 3D array 'A', and a binary 3-vector 'b':
> A = rand(5,5,5);
> b = [1, 0, 1];
>I want to remove the first entry of 'A' in dimensions where 'b' is 1. In
>the above example, I want
> result = A(2:end, 1:end, 2:end);
>This can be computed as (for arbitrary 'b')
> b += 1;
> result = A( b(1):end, b(2):end, b(3):end );
>But how can I do something similar if 'A' is N-dimensional? I can't
>think of any way of doing that.
>
>Søren
>
>
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.
Ben