Suppose I have several lists:
lst1={{{x1,y1},{dx1,dy1}},{{x2,y2},{dx2,dy2}},...};
lst2={{{x1,y1},dy1},{{x2,y2},dy2},...};
lst3={{{x1,y1},{dx1,{dy1n,dy1p}}},{{x2,y2},{dx2,{dy2n,dy2p}}},...};
where there can be several hundred entries in each list.
{xi,yi}
are measured data which can have errors {dxi,dyi}
.
Additionally these do not need to be symmetric, e.g. {dxi,{dyin,dyip}}
is also possible .
I want to write a function f[l_List]
which checks the form of the given list and then proceed in different ways.
Since the shape for a given list does not change, it is enough to check the first element.
For example:
g[l_List]:= If[ f[l[[1]]]=={{_,_},{_,_}} ,a ,b ]
Where a and b are further operations on that list. The problem I have is finding the correct formulation for the condition in the If-statement.
I came up with Dimensions[l[[1]]]=={1,2,2}
which works for distinguishing lst1
and lst2
, but fails for lst3
, since Dimensions[lst1[[1]]]==Dimensions[lst3[[1]]]=={1,2,2}
.
So the question is how this condition could look like.
Thanks in advance.
Additional question: How do I color my code like it is done in most questions on this side?
MatchQ[expr, {{_, _}, _}]
might be useful. $\endgroup$ – J. M. will be back soon♦ Aug 19 '17 at 16:12