| Author |
Comment/Response |
Bill Simpson
|
04/25/12 8:49pm
I am concerned that this may not a good example to learn Mathematica from. In particular I had to torture the code to some degree to get what I think your description meant by highest first position.
In[1]:= LIST={
{{1.,15.09},{1.,16.71},{1.,76.62},{1.,16.97},{1.,18.095}},
{{1.04307,15.74},{1.02334,17.1},{1.02284,78.37},{1.03536,17.57},{0.998342,18.065}},
{{1.07223,16.18},{1.03651,17.32},{1.0137,77.67},{1.03595,17.58},{1.02238,18.5}},
{{1.09013,16.45},{1.04668,17.49},{1.01305,77.62},{1.10607,18.77},{1.01741,18.41}},
{{1.02518,15.47},{1.00958,16.87},{0.997259,76.41},{1.05068,17.83},{0.989224,17.9}},
{{1.02783,15.51},{0.989826,16.54},{1.00783,77.22},{1.033,17.53},{1.00083,18.11}}
};
Reap[
oldhighpos=0;(*Pretend we have no prior highest first position*)
For[i=1,i≤Length[LIST],i++,
v=Sort[Map[First,LIST[[i]]],OrderedQ[{#2,#1}]&];(*sort first positions*)
If[v[[1]]>v[[2]],(*then we really have a new highest first position*)
newhighpos=Position[LIST[[i]],{v[[1]],_}][[1,1]];
If[oldhighpos≠newhighpos,Sow[LIST[[i]]];oldhighpos=newhighpos]
]
]
][[2,1]]
Out[2]= {
{{1.04307,15.74},{1.02334,17.1},{1.02284,78.37},{1.03536,17.57},{0.998342,18.065}},
{{1.09013,16.45},{1.04668,17.49},{1.01305,77.62},{1.10607,18.77},{1.01741,18.41}}
}
I do appreciate the effort you are putting into trying to be precise and clear about what you want the code to do and your concrete examples are very good. Without both of those it would be far more difficult to try to produce what you are asking for.
I expect someone can come up with a fairly simple functional programming example that will do the same thing.
URL: , |
|