frankzappa
Well-known member
Hello!
I need to write a program that can find the right indexes in a 2D array based off of sensor values and have no clue how to best solve this in an effecient way.
Basically I have two variables that I calculate from sensor values. They range from -1200 to 1200. I need the variables to represent two indexes in a 2D array. Every increment of 50 is one index so -1100, -1050, -1000, -950..... 950, 1000, 1050, 1100 need to represent indexes 0, 1, 2, 3.... 41, 42, 43, 44 for example. The array is 45x45 in size.
If the two variables are for instance: 903 and 323 I want the program to find the closest matching indexes so in this case the indexes that correspond to 900 and 300. I then need to read the value in that array location.
Here is a pictorial representation of the array with some random values inside that I want to read based on the sensor values.
https://www.dropbox.com/s/5n5mf2bkhb7sftj/sheet.jpg?dl=0
Any ideas how I might do this?
I'm thinking either I need to compare the sensor value with two index values for instance to find which one is bigger/smaller or just average the values within a range of 50 and then write another function to find the index that matches with that value.
Any suggestions?
I need to write a program that can find the right indexes in a 2D array based off of sensor values and have no clue how to best solve this in an effecient way.
Basically I have two variables that I calculate from sensor values. They range from -1200 to 1200. I need the variables to represent two indexes in a 2D array. Every increment of 50 is one index so -1100, -1050, -1000, -950..... 950, 1000, 1050, 1100 need to represent indexes 0, 1, 2, 3.... 41, 42, 43, 44 for example. The array is 45x45 in size.
If the two variables are for instance: 903 and 323 I want the program to find the closest matching indexes so in this case the indexes that correspond to 900 and 300. I then need to read the value in that array location.
Here is a pictorial representation of the array with some random values inside that I want to read based on the sensor values.
https://www.dropbox.com/s/5n5mf2bkhb7sftj/sheet.jpg?dl=0
Any ideas how I might do this?
I'm thinking either I need to compare the sensor value with two index values for instance to find which one is bigger/smaller or just average the values within a range of 50 and then write another function to find the index that matches with that value.
Any suggestions?