I have the list
L=8;
indx = Range[-π, π, 2 π/L]
(* {-π, -((3 π)/4), -(π/2), -(π/4), 0, π/4, π/2, (3 π)/4, π} *)
Now I want to delete specific elements of this list, e.g -(π/2), 0, (3 π)/4
I make a new list which includes the values I wish to delete, i.e:
exvals={-(π/2), 0, (3 π)/4};
and
For[i = 1, i <= Length[exvals], i++, indx = DeleteCases[indx, exvals[[i]]]]
indx
(*={-π, -(π/2), -(π/4), π/4, (3 π)/4, π} *)
which works fine. I am wondering if there is a more compact way to do it without using For
DeleteCases[indx, exvals]
(should not change sorting order) orComplement[indx, exvals]
(will return sorted list). $\endgroup$DeleteCases[Alternatives @@ exvals]@indx
. $\endgroup$Complement
. Please post it as a reply $\endgroup$