from the following table we have,
Table[i,{i,0,4,1}]
we (0,1,2,3,4)
can we have somehow
(0,2,3,4)
?
a formula Table[i-....,{i,....,...}]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIf you want to remove specific entries, there are at least 10 ways to do it. One way could be to insert an If
inside the table. Something like
Table[If[i == 1, Nothing, i], {i, 0, 4, 1}]
If you want more general approach, need to give a more general problem. Otherwise, this is very specific problem. You could simply also remove the 1
from the output afterwords?
Help on Nothing
says
Nothing represents an element of a list that will automatically be
removed.
With the list
list = {0, 1, 2, 3, 4, 2, 9, 2, 10, 1};
you can combine FirstPosition
and Delete
Delete[list, FirstPosition[list, _?(# == 2 &)]]
in order to remove only the first time 2
appears
If you use DeleteCases
with Infinity
as level specification
DeleteCases[list, 2, Infinity]
you'll remove all instances of 2
Using position with Delete
:
Delete[Table[i, {i, 0, 4, 1}], {2}]
(*{0, 2, 3, 4}*)
Using element with DeleteElements
:
DeleteElements[Table[i, {i, 0, 4, 1}], {1}]
(*{0, 2, 3, 4}*)
Reap[{Do[If[i==1,Continue[]];Sow[i], {i,0,4}]}][[2,1]]
(* {0, 2, 3, 4} *)
And (for example):
Reap[{Do[If[i==1 || i == 5,Continue[]];Sow[i], {i,0,10}]}][[2,1]]
(* {0, 2, 3, 4, 6, 7, 8, 9, 10} *)
Reap[Scan[If[#==1,Nothing,Sow[#]]&]@Range[0,4]][[2,1]]
$\endgroup$