All entries of array except certain indices in octave/matlab

In Octave or Matlab, some times one needs to eliminate certain elements in an array.

For example, if

a=[10,20,30,40,50,60];

and suppose I want to create a matrix “b” such that it has all the elements of “a” except 20 and 40. This can be achieved by:

b=a(1:end~=2&1:end~=4);

The result is:

b =

   10   30   50   60

One thought on “All entries of array except certain indices in octave/matlab

  1. Pingback: John Henry

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>