How to leave out selected elements from a vector?
Bill Denney
wsloand at gmail.com
Thu Jul 17 06:41:53 CDT 2008
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
More information about the Help-octave
mailing list