I have a large list of 3 by 3 matrices such that the dimensions of the list for an example 100 matrices would be: {100,3,3}

I have written a function that locates all the matrices I do not want and returns their locations in a list, so if 4 matrices are found that fulfill this criteria an example returned list could be: {3,27,56,97}

What I want is to be able to delete the corresponding matrices at these locations so that my list of matrices will now have the dimensions: {96,3,3}

I am sure this is very simple, and I have tried using Drop[] and Delete[], but I cannot get them to operate at the correct level. Thanks in advance for any help!


1 Answer 1


When you already have a dontWantMat function that returns True or False to say you don't want or want a matrix, then you can use Select

Select[listOfMat, Not[dontWantMat[#]]& ]

If you want to use your list of positions with Delete, you have to be careful because Delete expects the form Delete[mats, {{p1},{p2},{p3},..}] where p1,... are the position. Here is a short example which helps you

locations = {4, 6};
Delete[{1, 2, 3, 4, 5, 6}, List /@ locations]

(* {1, 2, 3, 5} *)
  • $\begingroup$ Thank you, I will try and rewrite my function so that it gives a true or false answer, but that might be tricky for someone of my lack of Mathematica skills! Currently my function just gives me a list of the locations of my unwanted matrices. $\endgroup$
    – Jack
    Commented Dec 3, 2014 at 17:48
  • $\begingroup$ @Jack But you do calculate the locations. That's why I thought it is easier to directly extract it using Select. Let me edit my answer to give you a solution with Delete $\endgroup$
    – halirutan
    Commented Dec 3, 2014 at 17:53
  • $\begingroup$ Excellent! Thank you. I am sure the way I am going about things is not the most elegant, but I am learning, when I have the chance I will go back and rewrite. $\endgroup$
    – Jack
    Commented Dec 3, 2014 at 17:59

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.