help-octave
[Top][All Lists]
Advanced

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

Re: Excluding elements of a matrix


From: Carlo de Falco
Subject: Re: Excluding elements of a matrix
Date: Tue, 19 Dec 2006 18:51:34 +0100

On 12/19/06, Joseph Wakeling <address@hidden> wrote:
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'm not sure wether I would use it,
but the following works to _exclude_
a row from a matrix:

octave:1> a=rand(6)
a =
 0.521485  0.938092  0.484011  0.644393  0.434212  0.140854
 0.864065  0.046670  0.238477  0.703722  0.070686  0.254906
 0.046559  0.893918  0.966250  0.855052  0.663261  0.604906
 0.947887  0.820183  0.229400  0.129235  0.643138  0.394996
 0.938083  0.781628  0.863682  0.674376  0.214862  0.327598
 0.165440  0.873448  0.757351  0.489245  0.090996  0.059462
octave:2>a([1:rows(a)]!=5,:)
ans =
 0.521485  0.938092  0.484011  0.644393  0.434212  0.140854
 0.864065  0.046670  0.238477  0.703722  0.070686  0.254906
 0.046559  0.893918  0.966250  0.855052  0.663261  0.604906
 0.947887  0.820183  0.229400  0.129235  0.643138  0.394996
 0.165440  0.873448  0.757351  0.489245  0.090996  0.059462


Carlo


reply via email to

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