Please, I want to get a smooth curve between two points

조회 수: 51 (최근 30일)
SAMUEL AYINDE
SAMUEL AYINDE 2017년 7월 12일
댓글: Indrayani 2023년 7월 28일
Please, I need a smooth curve between two points. The result I get from the current algorithm is not interesting. Please, find attached picture. The curves are between two red + sign. The current code I am using is this:
x_k = [x_1 x_2]';
y_k = [y_1 y_2]';
plot( x_k, y_k, '+r' ); % plot the original points
n = numel(x_k); % number of original points
xi = interp1( 1:n, x_k, linspace(1, n, 10*n) ); % new sample points
yi = interp1( x_k, y_k, xi );
hold all;
plot( xi, yi ); % should be smooth between the original points
Please, help me take a look into my code, make necessary adjustment or give a better code to compute smooth curves. Thank you.

답변 (1개)

Gautham Sholingar
Gautham Sholingar 2017년 7월 18일
The premise of your question is a little misleading. The only way to connect two points is with a straight line. Could you clarify what you mean by draw a curve between two points?
This would make sense if you had a collection of several points and you were attempting to draw a smooth curve through these points.
You can use the code you have attached to get an interpolated version.
Alternatively you can use the curve fitting toolbox to get different types of fits for your data as shown below
figure
x_k = [1:2:10]
y_k = [2,8,10,11,22]
plot( x_k, y_k, '+r' ); % plot the original points
n = numel(x_k); % number of original points
xi = interp1( 1:n, x_k, linspace(1, n, 10*n) ); % new sample points
yi = interp1( x_k, y_k, xi );
hold on
plot( xi, yi ); % should be smooth between the original points
hold off
%%Alternatively you can use the curve fitting toolbox to get different fits
figure
f = fit(x_k',y_k','smoothingspline')
plot(f,x_k,y_k)
The following documentation link is a useful starting point for this: http://www.mathworks.com/help/curvefit/fit.html
Another approach for this is to use the polyfit function to fit a polynomial for your dataset as shown in the following doc link: http://www.mathworks.com/help/matlab/ref/polyfit.html
All of these approaches should be a good starting point for you to fit curves to your data.
  댓글 수: 1
Indrayani
Indrayani 2023년 7월 28일
I have traced some points on a png image. Those points shown by b+. I want to form a smooth cubic spline curve between these points . How to do that?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by