Match values to most similar from defined list


#1

Hi all,

New to Dynamo.

I am trying to take a list of unique values that range from 0.2 to 0.8 but would like to simplify them to lets say 4 types. So instead of 100 unique values between 0.2 and 0.8, I’d like each value to be replaced with the closest value out of a list of four values (0.2, 0.4, 0.6, 0.8). Ideally the number of values that will be matched to can be only a slider to test 4, 5, 6 values between 0.2 and 0.8.

 

Any help? I was originally able to do this fairly easily in Grasshopper using the “Find Similar Member” component but haven’t been able to find a similar solution that doesn’t involve a huge array of > and < nodes.

 

Thanks!


#2

Maybe this could work for you:

2014-10-24_142442


#3

Other option can be to define a function that is finding the closest number
01
This is the test of the function
def GetSimilar(NumList:var[],RefNum)
{
Diff=Math.Abs(NumList-RefNum);
IndOrd=SortIndexByValue(Diff);
NumList2=NumList[IndOrd];

return=NumList2[0];
}