help-octave
[Top][All Lists]
Advanced

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

Re: How to leave out selected elements from a vector?


From: Ben Abbott
Subject: Re: How to leave out selected elements from a vector?
Date: Thu, 17 Jul 2008 23:56:00 -0400


On Jul 17, 2008, at 7:41 AM, Bill Denney wrote:

Francesco Potorti` wrote:
Here is my question. In Mathematica, there exists a function called
Drop, which I often use to manipulate lists, e.g., Drop[ list, {m, n} ] returns the argument list with the elements m through n omitted from
the list (the resultant list is shorter for (n - m + 1) elements).

Does anything similar already exist in Octave? I know I can program it
myself, but I wouldn't want to reinvent the wheel. :)

Use indexing. For instance [list(1:m-1), list(n+1:end)] could do what
you want.

Assuming, as Michael did, that you want to remove elements from an
array, you can alternatively do
 list(m:n)=[];

And if you don't want to actually remove the value from your list, but
you just want to do a calculation on a subset (not quite what you asked, but often what you asked for is for this purpose), you can index the vector:
with the indexes themselves
list([1:m-1 n+1:length(list)])

or with a logical vector
mask = false(size(list));
mask(m:n) = true;
list(mask)

Have a good day,

Bill

I like the "end" feature as well.

list([1:m-1, n+1:end])

Ben





reply via email to

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