Order a list based on values in another list

geddonn's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.

Would [zl lace] or [vexpr] be of any use or should I look into doing this in jitter?

geddonn's icon

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.

geddonn's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This probably explains it a little better:

Roman Thilenius's icon
geddonn's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.

Here is the new patch:

Wetterberg's icon

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 :-/

geddonn's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.

Let me know if I'm still making no sense.

geddonn's icon

Got it working now.

Max Patch
Copy patch and select New From Clipboard in Max.

Can't help but think that it is a little more complicated that it needs to be though.

geddonn's icon

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.

seejayjames's icon

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...

Luke Hall's icon

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.

Floating Point's icon

or keep the zeros and vexpr +

Luke Hall's icon

Vastly improved Terry, I'm rusty!