2
$\begingroup$

I have a matrix

m={{10,2},{20,3},{30,4},{40,5},{50,6}}

I can find certain elements with this statement

list=Select[m,(10 < #[[1]] < 50 ) && (#[[2]] < 6) &]

and I get

{20,3},{30,4},{40,5}

How can I use DeleteCases to remove the items {10,2} and {50,6}? I know I can invert the logic on the Select case, but I'd like learn to use DeleteCases, but can't figure out the right syntax for the selection. A one dimensional list is more straight forward, but I'm having trouble generalizing to higher dimensions.

Also, can anyone point me to clear documentation on selection syntax, as I am only mimicing the syntax I see in working examples and that often doesn't work.

Thanks,

$\endgroup$

2 Answers 2

1
$\begingroup$
DeleteCases[m , _?(Not[10 < #[[1]] < 50 && #[[2]] < 6] &)]

{{20, 3}, {30, 4}, {40, 5}}

$\endgroup$
1
$\begingroup$

It is unclear just what criteria you're seeking. It is easy to "remove the first and last items" by Delete[m, 1] and Delete[m, -1] or

Delete[m, {{1}, {-1}}].  

What mathematical criteria do you wish to invoke?

$\endgroup$
1
  • $\begingroup$ What you offer is also useful, but I was looking for deleting certain elements which meet certain criteria. The fact that the selected items were the 1st and last items was just a coincidence. I will modify my original question $\endgroup$ Commented Apr 13, 2017 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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