0
$\begingroup$

This question is somehow a part II of this: Part I.

Here comes a small data sample as a minimal working example:

{{-5.`, -3, 24.89`, 
0.8079019748736321`, -1, -1}, {-4.977477477477477`, -3, 24.72`, 
0.8100409238103935`, -1, 1}, {-4.954954954954955`, -3, 24.54`, 
0.8122953345427153`, -1, 2}, {-4.932432432432432`, -3, 24.36`, 
0.8145539903185015`, -1, 0}, {-4.90990990990991`, -3, 24.19`, 
0.8167060089472148`, -1, -1}, {-4.887387387387387`, -3, 24.01`, 
0.8189737833735357`, -1, -1}, {-4.864864864864865`, -3, 23.84`, 
0.8211357279224385`, -1, -1}, {-4.842342342342342`, -3, 23.67`, 
0.823303331789986`, -1, 0}, {-4.81981981981982`, -2, 23.5`, 
0.8254770541856945`, -1, -1}, {-4.797297297297297`, -2, 23.32`, 
0.8277682452908253`, -1, 2}, {-4.774774774774775`, -2, 23.15`, 
0.8299553813547601`, -1, 1}, {-4.752252252252252`, -2, 22.98`, 
0.8321495854317591`, -1, 2}, {-4.72972972972973`, -2, 22.82`, 
0.8342399060011664`, -1, -1}, {-4.707207207207207`, -2, 22.65`, 
0.8364482241698246`, -1, 2}, {-4.684684684684685`, -2, 22.48`, 
0.8386633336338121`, -1, -1}, {-4.662162162162162`, -1, 22.31`, 
0.8408848961319084`, -1, 0}, {-4.63963963963964`, -1, 22.15`, 
0.843001699453557`, -1, 1}, {-4.617117117117117`, -1, 21.98`, 
0.8452350102456677`, -1, 1}, {-4.594594594594595`, -1, 21.81`, 
0.8474735570160751`, -1, 2}, {-4.572072072072072`, -1, 21.65`, 
0.8496066341065539`, -1, 0}, {-4.54954954954955`, -1, 21.49`, 
0.8517447815274005`, -1, 2}, {-4.527027027027027`, 0, 21.32`, 
0.8539977804973352`, -1, -1}, {-4.504504504504505`, 0, 21.16`, 
0.8561457246831677`, -1, 2}, {-4.481981981981982`, 0, 21.`, 
0.8582989136727225`, -1, 1}, {-4.45945945945946`, 0, 20.83`, 
0.8605668266689402`, -1, 0}, {-4.436936936936937`, 0, 20.67`, 
0.862731269804195`, -1, -1}, {-4.414414414414415`, 1, 20.51`, 
0.8649021245634532`, -1, 2}, {-4.391891891891892`, 1, 20.35`, 
0.8670798666925034`, -1, -1}, {-4.36936936936937`, 1, 20.19`, 
0.8692649521543424`, -1, 2}, {-4.346846846846847`, 1, 20.03`, 
0.8714577803779188`, -1, 1}, {-4.324324324324325`, 1, 19.88`, 
0.873550635695638`, -1, 0}, {-4.301801801801802`, 1, 19.72`, 
0.8757599471643019`, -1, 0}, {-4.27927927927928`, 1, 19.56`, 
0.8779776273998509`, -1, 1}}

This time we need only columns 1, 2, 3 and 6. The first column contains the x position, the second column the corresponding energy E, the third the time, while the sixth column has only integers regarding a classification.

Now I want to do the following. For every value of E we have several values of x with different classification. The possible integers of the sixth column are: {-1, 0, 1, 2}.

(a). I want to compute the mean value of the third column for the first value of E when the six column is either 1 or 2 (not -1 and 0). Then go to the next value of E and repeat the procedure. Thus we can follow the evolution of the mean value as a function of E.

(b). For the first value of E compute how many (the percentage) 1 and 2 with time (third column) < 23 exist. Then repeat this calculation for all the other values of E, so as to create a plot showing the evolution of this percentage as a function of E.

Any suggestions?

$\endgroup$
1
$\begingroup$

(a)

Mean[Cases[Data, {_, e_, x_, _, _, i_} /; e == # && (i == 1 || i == 2) -> {e, x}]] & /@ 
  Range[-3, 1]
(* {{-3, 24.63}, {-2, 23.025}, {-1, 21.8575}, {0, 21.08}, {1, 20.0725}} *)

(b)

lyes = Count[Data, {_, e_, t_, _, _, i_} /; e == # && t < 23 && (i == 1 || i == 2)]& /@ 
  Range[-3, 1]    
ltot = Count[Data, {_, e_, t_, _, _, i_} /; e == #]& /@ Range[-3, 1]
N[lyes/ltot]
(* {0., 0.285714, 0.666667, 0.4, 0.571429} *)

If, as indicated in a Comment, the values of e are not regularly spaced, they can be extracted directly from Data.

energies = Union[Cases[Data, {_, e_, t_, _, _, i_} -> e]]
(* {-3, -2, -1, 0, 1} *)

and Range[-3, 1] replaced by energies in the expressions above.

$\endgroup$
  • $\begingroup$ Time is the third column (I corrected the post). Now let me explain better point (b). Let's take the first energy level E = -3. It contains items where the sixth column is -1, 0, 1, 2. I want to find how many of these have 1 or 2 at the sixth column but also when time is lower than 23 (a combined criterion). If the number of the items is n and there is ntot items with E = -3 then the desired percentage is (n/not)*100. Then of course the same procedure should be repeated for all other energy levels. $\endgroup$ – Vaggelis_Z Feb 16 '15 at 16:51
  • $\begingroup$ Do you perhaps mean (n/{n + not))*100? $\endgroup$ – bbgodfrey Feb 16 '15 at 17:06
  • $\begingroup$ I tested your solution to my actual data file but there is a problem. You see in the real data file the energy is between -3 and 0 and can take also decimal figures (i.e., -1.1, etc), so Range[-3,0] does not work because the step is not known. $\endgroup$ – Vaggelis_Z Feb 16 '15 at 17:07
  • $\begingroup$ (n/not)*100 is the correct. n is the number of items with sixth column equal to 1 or 2 with third column less then 23, while not is the total amount of items for a given energy level. $\endgroup$ – Vaggelis_Z Feb 16 '15 at 17:09
  • $\begingroup$ Next, is shall handle the more general case you just introduced. $\endgroup$ – bbgodfrey Feb 16 '15 at 17:15

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.