Connecting Data points in a smooth curve

37 ビュー (過去 30 日間)
Mohammad Farhat
Mohammad Farhat 2018 年 7 月 19 日
コメント済み: Image Analyst 2018 年 7 月 22 日
How can I connect 2D data points in a smooth curve given that I can't use spline because it requires my x elements to be unique?
  4 件のコメント
Mohammad Farhat
Mohammad Farhat 2018 年 7 月 19 日
huge code and a lot of data points, but for simplicity the problem narrows down to having for example: x=[2 4 5 2 8 5]; y=[15 6 17 28 90 80]; if I spline my data, I get the following error: Error using chckxy (line 51) The data sites should be distinct. Error in spline (line 53) [x,y,sizey,endslopes] = chckxy(x,y);
So apparently, x elements should be unique.
Mohammad Farhat
Mohammad Farhat 2018 年 7 月 19 日
Thanks Aquatris, but I can't average

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

採用された回答

Akira Agata
Akira Agata 2018 年 7 月 20 日
You can do this task by applying the method used in the 2nd example in spline function help page.
The following is an example:
% Your data
x = [2 4 5 2 8 5];
y = [15 6 17 28 90 80];
% Cubic spline data interpolation
t = 1:numel(x);
xy = [x;y];
pp = spline(t,xy);
tInterp = linspace(1,numel(x));
xyInterp = ppval(pp, tInterp);
% Show the result
figure
plot(x,y,'o:')
hold on
plot(xyInterp(1,:),xyInterp(2,:))
legend({'Original data','Spline interpolation'},'FontSize',12)
  2 件のコメント
Mohammad Farhat
Mohammad Farhat 2018 年 7 月 21 日
編集済み: Mohammad Farhat 2018 年 7 月 21 日
thanks that was helpful, turns out i have another problem and maybe spline isnt the answer at all because i guess it connects consecutive data points y_x and y_x+1, and I dont want this, so maybe the only solution is some graphic tool? is there any?
Image Analyst
Image Analyst 2018 年 7 月 22 日
This looks like a 1-D situation, not a 2-D situation. You have one input/independent/x value, and one output/dependent/y value for each input value. That's 1-D, even if they can be plotted in an x-y plane.
Attach your data, and show exactly what you'd like as the output. Maybe you just want interp1() but you just have to average the values that don't have unique x values. Or else add a tiny bit of noise to the x values to separate them.

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

その他の回答 (0 件)

カテゴリ

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