I have a matrix which contain rotated ellipses and points, how can I check if the element in the position {i,j} is either a point or an ellipse?

the code is a bit longer but the structure is like:

matrix = table [ if[condition] , Rotate[Circle, parameters[[i,j]]] ,Point [[i,j]],{j,1,900},{i,1,900}]

then I use Graphics over that matrix but I don't want to show the points, that's why i am asking how to detect the points

  • $\begingroup$ I don't understand the question. It would be best to give an example of such a matrix (a small one, as small as possible while still illustrating the problem) $\endgroup$ – Szabolcs May 28 '16 at 19:10
  • $\begingroup$ i updated the first post $\endgroup$ – Alucard May 28 '16 at 19:23

headF1 gets the Head of the expression in the specified part of the matrix. headF2 uses the fact that Part 0 of an expression is its Head.

headF1= Head[#[[## & @@ #2]]] &;
headF2= #[[## & @@ #2]][[0]] &; 

mat = RandomChoice[{Ellipse[], Point[]}, {5, 3}]

{{Point[], Point[], Ellipse[]}, {Point[], Ellipse[], Ellipse[]}, {Ellipse[], Point[], Ellipse[]}, {Point[], Ellipse[], Ellipse[]}, {Ellipse[], Ellipse[], Ellipse[]}}

headF1[mat, {2, 3}]


headF2[mat, {2, 3}]


  • $\begingroup$ nvm it works but it gives me Rotate, thanks $\endgroup$ – Alucard May 28 '16 at 19:25
  • $\begingroup$ can you explain me what the #s do in this case? $\endgroup$ – Alucard May 28 '16 at 19:29
  • $\begingroup$ @Alucard, you can use headF1[mat, {2, 3}] /. Rotate -> Ellipse. Or change the definition headF1 = Head[#[[## & @@ #2]]]/. Rotate -> Ellipse &. $\endgroup$ – kglr May 28 '16 at 19:30
  • $\begingroup$ @Alucard, #1, #2 are Slots, used as place-holders for un-named arguments. The pure Function headF1 does the same thing as the function with named arguments headF[ matrix_, part : {_, _}] := Head[matrix[[Sequence @@ part]]]. $\endgroup$ – kglr May 28 '16 at 19:35
  • $\begingroup$ ok i thought i had solved this but it seems this problem is out of my league. how can i force Graphics to act as i wish upon the matrix ? only the points should be transparent or not elaborated at all $\endgroup$ – Alucard May 28 '16 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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