Order a list based on values in another list

    Mar 17 2012 | 8:39 pm
    Hi, I'm having a problem trying to reorder the list on the right(in the patch) based on the order of the list on the left(in the patch).
    I don't want to have to unpack anything because this process needs to work on any list length.
    Would [zl lace] or [vexpr] be of any use or should I look into doing this in jitter?

    • Mar 17 2012 | 8:51 pm
      I should explain that the list on the right (L R) is the lift side and right side of a shape detected from a webcam. The list on the left(I, X) is the X vale of the center of the object. The X value is already ordered based on which object is detected first but the left and right values are not ordered yet.
    • Mar 17 2012 | 8:59 pm
      This probably explains it a little better:
    • Mar 17 2012 | 9:02 pm
      zl nth
    • Mar 17 2012 | 10:14 pm
      Hmm, I'm not sure that will help.
      I've made another patch. This one is an attempt to test each X value against the L and R values.
      So I want data to come out like this:
      xvalue 1 lr value 1 lr value 2 lr value 3 xvalue 2 lr value 1 lr value 2 lr value 3
      Then I need to find a way to order the list of lr values based on whether x is both greater than L and less than R.
      Unfortunately printing to the max window shows the values coming out in the wrong order.
      Here is the new patch:
    • Mar 17 2012 | 10:29 pm
      wait, so you want this to work with lists "of any length", but the data is in sets of four values, right? xval Ir Ir Ir sets.
      You need to explain what you're expecting to get out a lot better. Also, you're not telling us what you want changed about the patch(es) you post here - you say you don't want to unpack, yet I see unpack and iter all over the place :-/
    • Mar 17 2012 | 10:43 pm
      Sorry my explanation wasn't great, I was having trouble working out exactly what I needed to do to get to the result.
      Hopefully this next patch will illustrate it better.
      If you press the button marked 'Go' you should see in the max window four rows of data.
      0 0 0 0 5 15 0 0 0 0 0 0 0 0 85 95 15 25 0 0 0 0 0 0 0 0 35 45 0 0 0 0
      As you can see the patch is looking for whether the X value is somewhere between the L and R values. It then has placed the L and R values in the list based on which place the X value was in the list.
      My problem now I guess, is getting rid of the 0's while retaining the position of the L and R values.
      So from the above list of values I want to get one list: 15 25 35 45 5 15 85 95
      any ideas on how to achieve this would be great. Also any ideas on a simpler way of achieving this would be great.
      As I said before this should work on any amount of X values and pairs of LR values.
      Let me know if I'm still making no sense.
    • Mar 17 2012 | 10:56 pm
      Got it working now.
      Can't help but think that it is a little more complicated that it needs to be though.
    • Mar 17 2012 | 10:58 pm
      Doing the close and reopen patch test seems to show that it only works after the 2nd press of the Go button. Can't seem to figure out why.
    • Mar 18 2012 | 1:17 am
      I haven't seen the patches (no Max here) but you might try [zl filter] if you haven't, gets rid of the 0's and gives you index numbers for everything. might be helpful somewhere...
    • Mar 19 2012 | 12:25 am
      If you [substitute] the occurrences of each 0 for a 1 then you can multiply the four lists item by item using [vexpr] and you'll have the desired output list.
    • Mar 19 2012 | 1:13 am
      or keep the zeros and vexpr +
    • Mar 19 2012 | 10:31 pm
      Vastly improved Terry, I'm rusty!