How to put the marker data over the curve fitting line?

조회 수: 5 (최근 30일)
Oded Ben Tsedek
Oded Ben Tsedek 2021년 8월 16일
편집: Scott MacKenzie 2021년 8월 16일
Hello, I'm using curvefit with 555 data markers.
the default settings put the curve fit line over the data points. How do I reverse the order?
  댓글 수: 5
Oded Ben Tsedek
Oded Ben Tsedek 2021년 8월 16일
function [fitresult, gof] = createFit(t_new, x)
%CREATEFIT(T_NEW,X)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : t_new
% Y Output: x
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 16-Aug-2021 14:46:40
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( t_new, x );
% Set up fittype and options.
ft = fittype( 'poly2' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'x vs. t_new', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 't_new', 'Interpreter', 'none' );
ylabel( 'x', 'Interpreter', 'none' );
grid off
Scott MacKenzie
Scott MacKenzie 2021년 8월 16일
You note: the default settings put the curve fit line over the data points. That's not what I see. My plot has the points over the curve fit line.
Perhaps post the data and an image showing the plot you are seeing.

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

답변 (2개)

Oded Ben Tsedek
Oded Ben Tsedek 2021년 8월 16일
The data and the graph

Scott MacKenzie
Scott MacKenzie 2021년 8월 16일
편집: Scott MacKenzie 2021년 8월 16일
You posted your reply comment as an answer. Oops.
But, I see your point. And I'll try to explain here as an answer (although I'm not sure if this is exactly what you are after).
It seems the figure in the Curve Fitting Toolbox is different from the figure generated if you save the code and run it from the MATLAB Editor. The 1st figure below is for your data. It was generated from the curve-fitting code after saving the code and running it from the MATLAB Editor. The data points (blue) are an exact fit with the model. This makes it difficult to distinguish the points from the line (red). The 2nd figure is a zoomed-in segment which reveals that the points are indeed on top of the line, which is what you want.
So, if you save the code and run it from the MATLAB Editor, you'll get the figure you want.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by