MATLAB: Fit a curve along points through starting and end point

curve fittingplotstarting point

I have some points with each an x and y value. I want to fit a curve somehow along these points, but not necessarily through these points. Except for the starting and endpoint, where the curve has to go through. The point curve looks a bit like sin/cos, so i think a fourier fit would work. How do i get to this, but with fixed start and endpoint?

Best Answer

Use fit(): https://www.mathworks.com/help/curvefit/fit.html and specify the weights for each point
x = % your data points

y = % your data points
weights = [100 ones(1, numel(x)-2), 100]; % give a much higher weight to 1st and last point.
fit(x, y, 'sin8', 'Weights', weights);
sinx fittype series seems suitable for your data.
Related Question