adding same entry index number to coll?

R_Gol's icon

when I'm writing manually inside coll I can have same entry:

0, 500;
1, 455;
2, 667;
1, 800;
0, 4500;

and so on..
When I try to write into coll from outside using message box - if I try to write an entry I already using it will subtitute it instead of adding it in a new line.

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

Source Audio's icon

When you try to recall index from coll, you will se that this manual entry using several indexes with same address makes no sense.
Only one line will get output, depending on sorting order.
Only that at some point warning for that disappeared from coll text editor.

R_Gol's icon

let's say I have three groups:
Group 0
Group 1
Group 2

when pressing the number 0 I would like to store whatever value of x my mouse was at and store that into coll.
when pressing the number 1 I would like to store whatever value of x my mouse was at and store that into coll.

same with the number 2.

then I will be able to compare the x values of those groups with an input number and change the output accoridngly

here is an example of what I mean. This is why I want multiple indexes with the same value inside coll.

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

Source Audio's icon

you can not have multiple indentical indexes.
If you want to add more values into same index, use merge message.
Coll help file is very easy to read.
But maybe you need differnt data structure for your comparisons.

R_Gol's icon

So I'm using merge to add more values to the same index.
here is the updated patch:

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

the part of the patch on the right hand side that should output the closest much of x axis is not recognize the fact I store more then 1 value in the index, rather is make the comparison only with the first value at each index.

how can I apply that system for each value at any index?

Thanks!

R_Gol's icon

if to try and explain better.
Assuming I have those values in the Coll object:

0, 10 20 30;
1, 5 15 25;

if the value I compare (x axis from mouse) is 8 the output of closest much should be 0(index o)
if the value I compare is 17 the output should be 1(index 1)

the way the patch is now the comparison is not made with the other values in the indexes rather only with the first value at each index(either 10(index 0) or 5 (index 1).

Source Audio's icon

here is what you asked for, to get index of closest match

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

R_Gol's icon

Thank you very much!
What is those value at the 'xxx' Coll?
How can I also display the closest value match and not only the index of that value?

Source Audio's icon

values in xxx coll are calculated distances to current mouse x position.
input list divided by current position, which would give value of 1. for exact match.
But we want smallest deviation value, and that's abs(1- .....) so that exact match will become 0.
lowest overall value in xxx coll is the winner.
You actually don't need all items in xxx coll, 1st item is enough,
but I placed full list there, hoping that together with vexpr, you will understand
what is going on in the patch.
-----
zl.sort reorders vexpr output so that smallest value becomes 1st item in the list.
Because when one queries coll to output lowest value (min) , it does so on given slot (which is per default 1) in all indexes.
If you want to catch closest value as well, you need to use reordered indexes from zl.sort, and query closest match in original coll using nth message.

You need coll for this job, zl and other list tools would fail,
because you could start without capturing positions for all 3 indexes,
or even add more capture indexes,
which would make it difficult to assign values and calculations.
------
Why did you not ask from the biginning that you need both and not only index
of closest match ?


here is the patch

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

I removed parts which were not needed.
you can delete cellblocks too, they are anyway slowing everything down
but I placed them for you to monitor the values in the colls while programming.







R_Gol's icon

Thanks for explaining.
I try to add an option to manualy adding and changing values using the textedit object.

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

The problem is that because the data is constantly dump into coll then into the textedit object I can't manually change the values, rather I need to disconnect the string that goes from coll object to preprend set >> textedit object

How can I fix that?

Source Audio's icon

You don't really need textedit, open coll own text editor and write what you want.
Changes will apply when you close the editor window.
If you want to do it externally, make a copy of coll points and use it to deal with textedit.

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


R_Gol's icon

edit:
When I connect the main coll index to the coll copy on the right hand side it will desplay the values I enter in a delay of 1 number. So if I press the key "1'' nothing is display in the textedit object. Only after I press again "1'' the first value is display (it should display both values)

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


R_Gol's icon

I solved the above using pipe:

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

R_Gol's icon

How does it possible to arrange cellblock object in assending order of indexes if I don't enter them in order?

example:

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


edit: I've added the message sort -1 -1 between dump and coll. It seems to work

R_Gol's icon

Edit: The main patch you shared working just fine with integer number but when I try to change the input to floating number it won't output the closest match and display is value:

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


Source Audio's icon

you should as first understand at least a bit about objects that you use.
Sorry, but I have no time to teach essentials in max.
screen points are ints, not floats.
if you want to use them as floats for whatever reason,
it is your decision, then follow your floats along the line to see where they land and what makes the difference.

P.S.
if you want to have float value as match at the end, then divide the end result
with 1000. instead of dividing screen input

leave the rest as is.


Roman Thilenius's icon

0, 500;
1, 455;
2, 667;
1, 800;
0, 4500;


let me ask back: if you now want to call 4500, how would you do that?

R_Gol's icon

True - there is no way I could call 4500 with this method I was thought about

R_Gol's icon

I don't understand were my mistake is.
I have chanced all the integer numbers marked in blue to be floating point number but the system is not outputting the closest match (marked in red)

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

Source Audio's icon

a short look at the patch :
I used that to avoid "divided by zero" errors when mouse is at point 0

You divide intput by 1000.
It can not pass through sel 0 - int
also adding 0.1 for zero is wrong, because your point 1 is 0.001

also this is wrong :

pack i f to nth $2 $1
what are you packing and what is output of nth message ?
reversed list $2 $1 instead of $1 $2 means ?????
--------
You are much better off with my advice to keep all ints, and divide by 1000.
at the very end, if you need that small value for whatever reason.
------------
I have no time at the moment to go through all changes you did, so here is
all float version, without mistakes, but in my eyes also without sense...

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

R_Gol's icon

working great! thank you so much

R_Gol's icon

Hi again,
So I try to make the same patch but to calculate the nearest value of two numbers (x,y)
Here is my take:

It seems that indeed a pair of number are written into Coll but no output of the nearest pair.
Where is my mistake?

Thanks!

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

Source Audio's icon

Problem is that you don't understand how that patch works.
message min to coll queries lowest number in slot 1.
How should that output closest match of 2 items in the coll ?
Even if calculations in vexpr would be done for both x & y
(which are not ) it would not work at ll.
--------
That patch does exactly what you asked for.
Not to work on a list.



R_Gol's icon

Is there any way to make this patch working with two input of numbers? meaning output the closest match of two items and not only one?

Thanks

Source Audio's icon

it could

double everything (name colls different for x and y)
and so get 2 results, 1st one for x, 2nd for y.

you don't really mean to calculate average of both entries, and output closest ?

for example, if you have mouse positioned at x 10 and y 600
and captured xy pairs (as you tried)
0, 20 100 444 1000 33 666;
1, 100 22 456 65 777 12;
2, 77 99 668 1200 56 789;

what would be closest common match ?
------------
If you find better solution to this, post it ...
by the way, are you really going to manually edit that long floats ?

my advice - go back to ints

R_Gol's icon

you don't really mean to calculate average of both entries, and output closest ?

No

what would be closest common match ?

I have no idea. there is no mathematic formula to calculate it?

by the way, are you really going to manually edit that long floats ?

It is more for deleting specific floats rather then write new ones

Source Audio's icon

If you don't know what you want to declare as closest match
then one can't look for any formulas.

R_Gol's icon

double everything (name colls different for x and y)
and so get 2 results, 1st one for x, 2nd for y.
you don't really mean to calculate average of both entries, and output closest ?

I double everything and changed the name of calls. one for x and one for y
Now I'm getting the closest match independently for x and for y. how can I calculate average of both entries, and output closest ?

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

Source Audio's icon

I don't understand what is average for you.
What do you take into average calculation ?
closest match x and closest match y ?
they will have different indexes anyway.
In that sense you should have calculated average of xy values in each index before getting closest average match.
Which again is different than getting the closest match of individual x and y points.

lets say one xy pair could have average of 0.3 but closest match 0.2
x = 0.4 y = 0.2
but the other pair with average 0.4 could have closest match 0.1
x = 0.1 y = 0.7

because average is x + y / 2
------
I asked you about averaging xy pairs at some point,
and the answer was no
see here


R_Gol's icon

I think I need to rethink the all patch. Thank you very much for helping until this point!

Source Audio's icon

It was not clear from the beginning what exactly you want to get
from coordinates on the screen.
If it is simply closest hit, like when you try to get the arrow in the
middle of the target, and you measure the distance middle to arrow hit, it has nothing to do with 2d xy coordinates, but direct distance point to point.

Is that what you are after ?
In that case you measure current cursor position distance to captured
point