I'm writing a research paper and want to plot something like this from my dataset

Basically it's a Matlab scatter plot with a lowess curve showing the average value at each bin
I've been searching Google for 2 days and couldn't find a solution or a piece of sample code to do that yet
Stack Overflow is now my last resort :)
This is the simplest code I can come up with. This assumes you have your data in x and y vectors.
It is possible to vectorize this, but it is not worth it. At least the way I found would make it unreadable and marginally more efficient, if at all.