Where does the problem lie? Are you surprised that the spline does not pass through the maximum data point? So are you just asking how to locate the maximum point, or are you worried that the smoothing spline seems to have missed that max?
Any smoothing tool will tend to reduce the peaks, increase the valleys. This is especially true of sharp peaks. Why? Because that is a location where the function is most inconsistent with the rest of the curve. So unless you have a nice, smooth, well-behaved maximum, then the smooth will tend to reduce it, to draw it down. Because it looks like it might be noise.
There are bumps in your data, clearly noise. So why should the smoothing tool not be willing to disbelieve just a little bit of that extreme point?
If you NEED to find the maximum, AND you believe that that peak is what you are looking for, then you NEED to use an interpolating spline, NOT a smoothing spline.
Ok, perhaps your question is not why does the curve not pass smoothly through the peak. Perhaps you are just trying to find out how to locate that maximal value.
How do you find a minimal point on a curve? The simple answer is to just use fminbnd, at least in one dimension. Or you could as easily use fminsearch. It will work fine here, though not quite as efficiently. But you want to find a maximum. The classic answer in optimization, as to how to find a max, is just find a minimum of the negative of your function. Multiply it by -1. Then use a minimization tool. Either fminbnd or fminsearch will suffice. (You could also use my SLM toolbox, which does have a tool in there that will locate the maximum or minimum point on a spline. But you don't need that here, and there is no reason to go that far.)
Best Answer