0
$\begingroup$

I have a list at 3dplot and I want to have a list the second element of which be equal to 0.2

sELECTdplot= Select[3dplot, (#[[2]] == 0.20 &)]
(***
 {{0., 0.2, -0.0793037}, {0.2, 0.2, -0.0903679}, {0.4, 
 0.2, -0.100867}, {0.6, 0.2, -0.111708}, {0.8, 0.2, -0.123335}, {1., 
 0.2, -0.135819}, {1.2, 0.2, -0.148896}, {1.4, 0.2, -0.162047}, {1.6,
 0.2, -0.174654}, {1.8, 0.2, -0.186165}, {2., 0.2, -0.196225}}
 **)

and after that I want to delete the second element of any sublist (removing 0.2 from all elements) for this reason I have used of

dELETTED= DeleteCases[sELECTdplot, 0.2, Infinity]
(***{{0., 0.2, -0.0793037}, {0.2, -0.0903679}, {0.4, 
 0.2, -0.100867}, {0.6, 0.2, -0.111708}, {0.8, 0.2, -0.123335}, {1., 
 0.2, -0.135819}, {1.2, 0.2, -0.148896}, {1.4, 0.2, -0.162047}, {1.6,
 0.2, -0.174654}, {1.8, 0.2, -0.186165}, {2., 0.2, -0.196225}}**)

Deleting just happened for {0.2, -0.0903679} the second element. it is because of when I copy one of 0.2s in the sELECTdplot they are originally are 0.20000000000000004. How can I get rid of this annoying case?! Also I cannot understand why must we use of Infinity in the DeleteCases. Without this we cannot reach to a desired result.

$\endgroup$
  • 1
    $\begingroup$ The Infinity is necessary because DeleteCases operates on Level 1, by default (i.e. it's checking to see if each of the lists is equal to 0.2, which clearly isn't the case). You could also do DeleteCases[sELECTdplot, 0.2, {2}], because the third argument forces DeleteCases to look at the quantities at Level 2, which are all of the numbers in the 3-element lists. $\endgroup$ – march Feb 26 '16 at 7:27
  • 3
    $\begingroup$ @Ackaran - I don't understand how you have defined a variable as 3dplot? In your data file you have 3dplot = ...... which of course gives an error because variables can't begin with numbers. $\endgroup$ – Jason B. Feb 26 '16 at 8:11
  • $\begingroup$ I understood this error, I could not remove that $\endgroup$ – Unbelievable Feb 26 '16 at 8:17
  • 1
    $\begingroup$ 3dplotwill be interpreted as 3*dplot. As stated by @JasonB, you can simply remove the second column, without any need for matching. $\endgroup$ – Yves Klett Feb 26 '16 at 8:21
2
$\begingroup$

There is no reason to use DeleteCases here, you can use Part to remove the middle column.

Select[dplot, (#[[2]] == 0.20 &)][[All, {1, 3}]]
(* {{0., -0.0793037}, {0.2, -0.0903679}, {0.4, -0.100867}, 
{0.6, -0.111708}, {0.8, -0.123335}, {1., -0.135819}, {1.2, 
-0.148896}, {1.4, -0.162047}, {1.6, -0.174654}, {1.8, -0.186165}, 
{2., -0.196225}} *)
| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.