Fit a curve along points through starting and end point

58 ビュー (過去 30 日間)
Stefan Lang
Stefan Lang 2020 年 10 月 1 日
回答済み: Ameer Hamza 2020 年 10 月 1 日
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?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 1 日
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.

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 10 月 1 日
編集済み: KALYAN ACHARJYA 2020 年 10 月 1 日
You can fit the curve in number od ways, see which tyep perfectly fit as per your expectation
x_data=randi(10,[1,10])';
y_data=randi(10,[1,10])';
plot(x_data,y_data,'ro');
hold on
plot1=fit(x_data,y_data,'exp1');
%..........................^
plot(plot1,x_data,y_data);
Detail MATLAB docs here
If you just want connect the start point and end point only, plot the initail and end points of x and y data
x_data=randi(10,[1,10]);
y_data=randi(10,[1,10]);
plot(x_data,y_data,'ro');
hold on
plot(x_data([1,end]),y_data([1,end]));
  1 件のコメント
Stefan Lang
Stefan Lang 2020 年 10 月 1 日
編集済み: Stefan Lang 2020 年 10 月 1 日
Well this does fit a curve to my data, but the fitted curve does not go through the first and last point. How do i get this? If i have 10 points, the curve has to connect point 1 with point 10, but in between, follow (not exactly, but nearby) point 2 to 9.
So, start exactly at point 1, fit the curve from point 2 to 9, finish exactly at point 10.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by