[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Excluding elements of a matrix (Joseph Wakeling)
From: |
Muthiah Annamalai |
Subject: |
Re: Excluding elements of a matrix (Joseph Wakeling) |
Date: |
Wed, 20 Dec 2006 07:26:41 +0530 |
> Date: Tue, 19 Dec 2006 18:08:27 +0100
> From: Joseph Wakeling <address@hidden>
> Subject: Re: Excluding elements of a matrix
> To: Bill Denney <address@hidden>
> Cc: Octave users list <address@hidden>
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=UTF-8
>
> Bill Denney wrote:
> > You can do something like
> >
> > a = 1:10;
> > b = a([1:5 7:10])
>
> Sure; this is selectively _including_ elements of a vector/matrix (in
> this case, elements 1-5 and 7-10). I was wondering if there's a
> comparably simple notation for _excluding_ elements.
>
> The reason I ask is that, for example, if I want to remove element k
> from a given vector, there are special cases. I can't just write,
>
> a = a([1:(k-1) (k+1):columns(a)])
>
> because obviously I might have k=1 or k=columns(a).
>
> It would simplify things a lot if instead of having to write extra lines
> to take into account these special cases, there were a notation giving
> "everything but element k".
>
I think you can use this notation,
a = a([1:max(1,k-1) min(K+1,columns(a)):columns(a)])
-Muthu
- Re: Excluding elements of a matrix (Joseph Wakeling),
Muthiah Annamalai <=