help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Excluding elements of a matrix (Joseph Wakeling)


From: John W. Eaton
Subject: Re: Excluding elements of a matrix (Joseph Wakeling)
Date: Tue, 19 Dec 2006 21:24:47 -0500

On 20-Dec-2006, Muthiah Annamalai wrote:

| 
| > 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)])

You can, but it is not necessary.  If k == 1, then the first
expression is 1:0, or [](1x0).  If k == columns(a), then the second
expression is k+1:k, or [](1x0), so it just works.

jwe


reply via email to

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