MATLAB Answers

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

조회 수: 1(최근 30일)
Wesley 2021년 1월 20일
댓글: Wesley 2021년 1월 20일
load dataA.mat
f1 = fit(xAbove,yAbove,'smoothingspline','SmoothingParam',0.0001);%smoothingspline
hold on
load dataB.mat
[xx,ind] = sort(xBelow);
yy2 = smooth(xBelow,yBelow,0.5,'rloess');
%f2 = fit(xBelow,yBelow,'smoothingspline','SmoothingParam',1);%smoothingspline
%hold on


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,:) ;
  댓글 수: 6
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;
load dataA.mat
load dataB.mat
x = [xAbove;xBelow];
y = [yAbove;yBelow];
k = convhull(x,y);
hold on;
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by