# Help: Smooth a curve generated from a group of specified points

2 views (last 30 days)
Khanh on 18 Sep 2014
Commented: Star Strider on 19 Sep 2014
Hi,
I have 2 vector of x, y coodinates of points
x=[0 50 935 1870 1935 2805 3740 4675 5610 6545 6746 7480 7911 8415 8590 9004];
y=[300 600 716 892 900 990 1052 1071 1037 934 900 736 600 393 300 0];
length(x)=length(y)=16.
The first curve is generated by plot(x,y).
Because I want to smooth the orginal curve. From x, y vectors, I want to generate x', y' vectors with length(x')=length(y')=101. And the second curve is generated by plot(x',y').
Could someone please help me to do this?
I also created a script to do it, but the result wasn't same as the one I want.
My script:
clc
clear all
x=[0 50 935 1870 1935 2805 3740 4675 5610 6545 6746 7480 7911 8415 8590 9004];
y=[300 600 716 892 900 990 1052 1071 1037 934 900 736 600 393 300 0];
plot(x,y,'-o');
xnew=linspace(x(1),x(end),101);
ynew=spline(x,y,xnew);
figure
plot(xnew,ynew,'--o');
The curve generated by plot(x,y):
The curve generated by plot(x',y'):
The result I want to get:
Khanh.
##### 0 CommentsShow -1 older commentsHide -1 older comments

Sign in to comment.

### Accepted Answer

Star Strider on 18 Sep 2014
Using interp1 with the 'pchip' method will get you closer:
xi = linspace(min(x),max(x),101);
yi = interp1(x, y, xi, 'pchip');
figure(1)
plot(x, y, '+r')
hold on
plot(xi, yi)
hold off
grid
I experimented with resample, even though it is intended for signal processing. It is definitely not appropriate here.
##### 2 CommentsShow 1 older commentHide 1 older comment
Star Strider on 19 Sep 2014
My pleasure!

Sign in to comment.

### More Answers (1)

Salaheddin Hosseinzadeh on 18 Sep 2014
Hello Khanh, Please try to use resample rather than spline
doc resample
Simply resample your x and y value with same factor and then plot them.
Good Luck!
##### 1 CommentShow NoneHide None
Khanh on 19 Sep 2014
Thanks.

Sign in to comment.

### Categories

Find more on Interpolation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!