How do I plot a curve through these points?

조회 수: 7 (최근 30일)
Guestsaint
Guestsaint 2016년 1월 10일
편집: Walter Roberson 2016년 1월 11일
I have arrays of x and y values (both of equal length) and plotted the following graph using plot(x,y):
I want to plot smooth curves through these points so that I end up with a bell-shaped curve on top, and a second curve through the points that lie along the bottom.
However when I try to use Basic Fitting to plot a curve, I get the error 'Repeated X values are not permitted when fitting with a cubic interpolating spline. Remove repeated values'.

답변 (1개)

Star Strider
Star Strider 2016년 1월 10일
You did not include your data (and I do not have the Curve Fitting Toolbox), but the unique function will likely help. You will likely need the first two outputs, something like this:
A = randi(9, 15, 2);
[Au, ia] = unique(A(:,1));
Aplot = A(ia,:);
where ‘A’ has the x-data in column 1, the y-data in column 2, and ‘Aplot’ is the sorted array with unique x-values and the first corresponding y-values the function found.
  댓글 수: 2
Guestsaint
Guestsaint 2016년 1월 10일
편집: Guestsaint 2016년 1월 10일
I used the unique function by adding this to my code:
[x_unique,ind] = unique(x);
y_unique = y(ind);
and then using plot(x_unique,y_unique).
I get the same points plotted as before but now when I try to plot curves through them using Basic Fitting I now get the error 'Matrix is singular to working precision'.
Star Strider
Star Strider 2016년 1월 10일
I’m not sure what you’re doing, but one possibility is that you’re attempting to fit a much higher-degree polynomial than your data can approximate. Reduce the order of the polynomial.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by