Hello everyone, how do you fit two curves into a closed curve?My code is as follows.

4 ビュー (過去 30 日間)
Wesley
Wesley 2021 年 1 月 20 日
コメント済み: Wesley 2021 年 1 月 20 日
load dataA.mat
%x1=dataA(:,1);
%y1=dataA(:,2);
f1 = fit(xAbove,yAbove,'smoothingspline','SmoothingParam',0.0001);%smoothingspline
%plot(f1,xAbove,yAbove)
plot(f1,'-r')
hold on
load dataB.mat
%x2=dataB(:,1);
%y2=dataB(:,2);
[xx,ind] = sort(xBelow);
yy2 = smooth(xBelow,yBelow,0.5,'rloess');
plot(xx,yy2(ind),'r-')
%f2 = fit(xBelow,yBelow,'smoothingspline','SmoothingParam',1);%smoothingspline
%plot(xBelow,yBelow)
%xBelow(1)=xAbove(1);
%yBelow(end)=yAbove(end);
%hold on

回答 (2 件)

KSSV
KSSV 2021 年 1 月 20 日
load dataA ;
load dataB ;
C1 = [xAbove yAbove] ;
C2 = [xBelow yBelow] ;
% MErge them
C = [C1 ;C2] ;
idx = boundary(C(:,1),C(:,2)) ;
C = C(idx,:) ;
plot(C(:,1),C(:,2))
  6 件のコメント
Wesley
Wesley 2021 年 1 月 20 日
And the curve cannot be derivated and be searched for extreme points
Wesley
Wesley 2021 年 1 月 20 日
My idea is similar to the idea of piecewise function fitting, where the critical points are equal at the nodes to realize the fitting of a closed curve.

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


Raghav Gnanasambandam
Raghav Gnanasambandam 2021 年 1 月 20 日
I am not sure whether it is actually needed to combine the two curves. I am assuming you just need to find the closed curve for the whole data. Depending on how you want to fit a closed curve, you can use either boundary() or convhull().
load dataA.mat
load dataB.mat
x = [xAbove;xBelow];
y = [yAbove;yBelow];
k = boundary(x,y);
hold on;
plot(x(k),y(k));
or
load dataA.mat
load dataB.mat
x = [xAbove;xBelow];
y = [yAbove;yBelow];
k = convhull(x,y);
hold on;
plot(x(k),y(k));
Hope this helps.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by