How to plot a fit object without extrapolation?

조회 수: 8 (최근 30일)
Katharina
Katharina 2014년 9월 30일
댓글: Sean de Wolski 2014년 10월 1일
Hi, I am looking for a way to plot a curve fit object but without the extrapolation at the beginning and the end of the curve. My code for the current graph is as follows:
% Fit
[Fit.(string).fitresult, Fit.(string).gof] = fit( xData1, yData1, ft, 'Normalize', 'on' );
hc(k) = plot(xData1, yData1, '.', 'Marker', markerlist(k),'MarkerEdgeColor',colorlist(k,:),'MarkerFaceColor',colorlist(k,:));
hold on
% Plot fit
ha = plot(Fit.(string).fitresult);
Which generates this figure:
Since the end line, especially for the red curve, is not right, I need to remove that part. Does anyone have a solution? Thanks in advance! Best regards, Katharina

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 9월 30일
You can pass 'XLim' into fitresult's plot to plot only over a specific range in x.
  댓글 수: 2
Katharina
Katharina 2014년 10월 1일
Sorry, I don't know how to unaccept an answer... Anyhow, it doesn't work for:
% Fit
[Fit.(string).fitresult, Fit.(string).gof] = fit( xData, yData, ft, 'Normalize', 'on' );
ha = plot(Fit.(string).fitresult, 'XLim', [min(xData) max(xData)]);
yields an error message:
Error using cfit/plot>parseinput (line 328)
Must specify both XDATA and YDATA.
Doesn't the XLim option only work for sfit objects and not for cfit objects? That is how I understand the documentation.
Sean de Wolski
Sean de Wolski 2014년 10월 1일
Sorry, you're right and that certainly looks like a good enhancement request for cfits.
It looks like you'll have to evaluate it at the query points explicitly and then plot the x/y vectors.
For example:
x = 1:8;
y = fitresult(x); % evaluate at x
plot(x,y) % plot the vectors

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by