plot smooth curve through discreet points

3 ビュー (過去 30 日間)
Reginald
Reginald 2015 年 1 月 20 日
コメント済み: Nor Affendy Yahya 2018 年 8 月 1 日
I have discreet data for x=[38.7330 -19.2503 -50.7264 -65.8133 -71.4051 104.5372 51.8456 24.5807 12.5377 8.4663 -8.4663 -12.5377 -24.5807 -51.8456 -104.5372 71.4051 65.8133 50.7264 19.2503 -38.7330]; and y=[-0.5000 -0.4375 -0.3750 -0.3125 -0.2500 -0.2500 -0.1875 -0.1250 -0.0625 0 0 0.0625 0.1250 0.1875 0.2500 0.2500 0.3125 0.3750 0.4375 0.5000];
when I plot for x and y the curve is not smooth How to make the plot smooth curve passing through points and maintaining the shape

採用された回答

Thorsten
Thorsten 2015 年 1 月 21 日
編集済み: Thorsten 2015 年 1 月 21 日
First you have to interpolate x depending on y. Next, you have to do the interpolation separately for each of the discontinuous segments. Since the function has discontinuities after every 5 data points, we don't have to figure out the discontinuities but interpolated every set of 5 points separately (the xi_end, yi_end denote the last data point of the previous segment to plot the horizontal lines):
ind0 = 1:5; xi_end = NaN; yi_end= NaN;
for i = 1:numel(y)/numel(ind0)
ind = ind0 + 5*(i-1);
yi = linspace(y(ind(1)), y(ind(end)));
xi = interp1(y(ind), x(ind), yi, 'spline');
plot([xi_end xi], [yi_end yi])
hold on
xi_end = xi(end);
yi_end = yi(end);
end
  1 件のコメント
Reginald
Reginald 2015 年 1 月 22 日
Perfect the above code works Thank you Thorsten

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

その他の回答 (2 件)

Alessandro Masullo
Alessandro Masullo 2015 年 1 月 20 日
xx = linspace(min(x),max(x),100); yy = spline(x,y,xx); figure,plot(x,y,'o',xx,yy)
  1 件のコメント
Nor Affendy Yahya
Nor Affendy Yahya 2018 年 8 月 1 日
this is the most simple n elegant solution. Thanks appreciated so much

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


Reginald
Reginald 2015 年 1 月 21 日

This is the original plot with x and y

This plot is with above code totally different. As I know microsoft excel can plot smooth plots in scatter plot with line. Is it not possible to apply the same algorithm in matlab ?

カテゴリ

Help Center および File ExchangeSmoothing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by