How to find the closest value to the average in an array?
6 views (last 30 days)
I get a different one dimentional array for different inputs. Now, I want to take the average value of the array, and find the value that is closest to it.
For example if the array output is like this:
a = [1,2,3,4,5,6,7]
Then average will be 4.14, which is closest to 4.
So, the answer should be 4.
How can I do it?