x1=[40,10,145,125];
x2=[20,15,30,35,35,45,50,50,100,90,100,150,150,210,250,350,370];
y1=[100,400,50,10];
y2=[950,1250,1600,1300,1200,1100,1000,900,750,1000,1100,700,800,450,550,0,200];
createFit1(x2,y2)
hold on
createFit(x1,y1)
%hold on ;
%createFit1(x2,y2);
点击文件➡️选择 generate code导出生成这条曲线的代码。
function [fitresult, gof] = createFit(x1, y1)
%CREATEFIT(X1,Y1)
% Create a fit.
%
% Data for 'curve1' fit:
% X Input : x1
% Y Output: y1
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% 另请参阅 FIT, CFIT, SFIT.
% 由 MATLAB 于 28-Dec-2021 14:42:23 自动生成
%% Fit: 'curve1'.
[xData, yData] = prepareCurveData( x1, y1 );
% Set up fittype and options.
ft = fittype( 'poly1' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
% Plot fit with data.
%figure( 'Name', 'curve1' );
h = plot( fitresult, xData, yData );
hold on
legend( h );
% Label axes
xlabel 湖区蒸散量(10^4m^3)
ylabel 水量(10^4m^3)
%grid on
hold on
function [fitresult, gof] = createFit1(x2, y2)
%CREATEFIT1(X2,Y2)
% Create a fit.
%
% Data for 'curve2' fit:
% X Input : x2
% Y Output: y2
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% 另请参阅 FIT, CFIT, SFIT.
% 由 MATLAB 于 28-Dec-2021 14:43:06 自动生成
%% Fit: 'curve2'.
[xData, yData] = prepareCurveData( x2, y2 );
% Set up fittype and options.
ft = fittype( 'poly1' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
% Plot fit with data.
figure( 'Name', 'curve2' );
h = plot( fitresult, xData, yData );
hold on
legend( h );
% Label axes
xlabel x2
ylabel y2
%grid on
hold on