1
$\begingroup$

I am using Select to take values from a multidimensional list based on a previously calculated range.

The list is of time and position of a particle over time steps done for multiple particles. The structure of the list meansqdCut is

meansqdCut = {{{t10,x10},{t11,x11}},{{t20,x20}{t21,x21}},..,{{tn0,xn0},{tn1,xn1}}}

Where t10 is first particle, 0th time step. So for example (2 time steps)

meansqdCut = {{{0,0},{1,5}},{{0,0},{1,8}},...,{{0,0},{1,6}}}

I have previously plotted the data and I'm using the first maximum of position as the upper limit of the range. Using

peaks = FindPeaks[meansqdCut[[#, All, 2]]] & /@ Range [1, upper]

finds the position of the maxima and I'm using the first maximum to specify the higher extent of the range. I want to take all elements of the list for each particle up to a point where the x value is greater than the maximum specified by peaks.Then using the select function:

meansqdCutMax = 
  Select[meansqdCut[[#]], 0 <= #[[1]] <= peaks[[#, 1, 1]] &] & /@ 
   Range [1, 10]

Where Range[1,10] means performing this operation on particles 1 to 10. Each particle will have a different range of elements I want to select.

This gives me multiple errors saying that "The expression {0.943462,0.} cannot be used as a part specification" and I'm not sure why this arises.

If I replace the upper limit of the range with a number so

meansqdCutMax = 
      Select[meansqdCut[[#]], 0 <= #[[1]] <= 100 &] & /@ 
       Range [1, 10]

then I get the desired output. So I'm presuming it is a problem with the # in the upper limit.

Thanks in advance!

$\endgroup$
  • $\begingroup$ What is upper? Is it Length@meansqdCut? What is the structure of meansqdCut? Is it { {pos of particle 1 at time t0, pos of particle 2 at time t0}, {pos of particle 1 at time t1, pos of particle 2 at time t1}, ...}? Are you using FindPeaks to find which of the second elements is greater? What are you Selecting for? Point is: It's a little unclear what you're trying to do. $\endgroup$ – march Nov 10 '15 at 18:22
  • $\begingroup$ Hi, sorry, it is a bit unclear, I'll edit my question and make it clearer. $\endgroup$ – jj364 Nov 10 '15 at 19:03
  • $\begingroup$ I have removed the 'upper' and changed it to 10. This specifies which particles I want to perform this operation on. $\endgroup$ – jj364 Nov 10 '15 at 19:13
  • 1
    $\begingroup$ I'm guessing that in peaks[[#, 1, 1]], the # is supposed to be the Slot for the outer function that is being Mapped over Range[1, 10], but since it is insede the test function for Select, you are feeding elements of meansqdCut[[#]] to it. How about this instead: Cases[meansqdCut[[#]], a_ /; 0 <= a[[1]] <= peaks[[#, 1]]] & /@ Range[1, 10] $\endgroup$ – march Nov 10 '15 at 19:20
  • $\begingroup$ I think it would be beneficial to add a more complicated example of meansqdCut, one where meansqdCutMax actually produces something different than just the original list, because we might be able to come up with something a little cleaner. $\endgroup$ – march Nov 10 '15 at 19:22
1
$\begingroup$

I've managed to get this working using one of the suggestions by @march

I'm guessing that in peaks[[#, 1, 1]], the # is supposed to be the Slot for the outer function that is being Mapped over Range[1, 10], but since it is insede [sic] the test function for Select, you are feeding elements of meansqdCut[[#]] to it. How about this instead: Cases[meansqdCut[[#]], a_ /; 0 <= a[[1]] <= peaks[[#, 1]]] & /@ Range[1, 10]march

My final line of code was:

meansqdCutMax = Cases[meansqdCut[[#]], a_ /; 0 <= a[[1]] <= peaks[[#, 1, 1]]] & /@ Range[1, upper];

Which solved the problem with the use of Slots for the Select and the Mapping.

I'm sorry for my lack of clarity on this question, I'm very new to Mathematica (as you can all probably tell)! Thank you very much for your help @march

$\endgroup$

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.