필터 지우기
필터 지우기

Plot multi curve in one figure

조회 수: 2 (최근 30일)
Tesla
Tesla 2022년 5월 25일
댓글: Voss 2022년 5월 28일
I am trying to plot many curve in one figure with different color and size.
But when I am trying to do that I got strange error.
Here my code
function [fitresult, gof] = createFits1(x, y)
%% Initialization.
x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6];
%y = [0.001, 0.00111499, 0.0011926, 0.0013699, 0.00161633, 0.00192075, 0.00274991, 0.00357156]; % for 100% 0.64
% x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6]';
% y = [0.001, 0.001161, 0.00141484, 0.0021995, 0.00408401, 0.00454675, 0.0067192, 0.00987622]'; % 10% 0.54 + 90% 0.99
y = [0.001, 0.00117728, 0.00146081, 0.00215119, 0.00307794, 0.00398234, 0.00619084, 0.00696612];
% Initialize arrays to store fits and goodness-of-fit.
fitresult = cell( 10, 1 );
gof = struct( 'sse', cell( 10, 1 ), ...
'rsquare', [], 'dfe', [], 'adjrsquare', [], 'rmse', [] );
%% Fit: 'Mooney (1951)'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( '0.001*(exp((b*x)/(1-x/a)))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0];
opts.StartPoint = [1 1];
opts.Upper = [1 100];
% Fit model to data.
[fitresult{1}, gof(1)] = fit( xData, yData, ft, opts );
plot( fitresult{1}, xData, yData );
legend('y vs. x', 'Mooney (1951)', 'Location', 'NorthEast', 'Interpreter', 'none' );
hold on
%% Fit: 'Krieger and Dougherty (1959)'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( '0.001*(1-x/a)^(-b*a)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0];
opts.StartPoint = [1 1];
opts.Upper = [1 100];
% Fit model to data.
[fitresult{2}, gof(2)] = fit( xData, yData, ft, opts );
plot( fitresult{2} ,xData, yData,'LineWidth',10);
legend('y vs. x', 'Krieger and Dougherty (1959)', 'Location', 'NorthEast', 'Interpreter', 'none' );
hold on
  댓글 수: 2
Torsten
Torsten 2022년 5월 25일
It would be interesting to know the error message and location.
Tesla
Tesla 2022년 5월 25일
The error is:
Error in cfit/plot (line 50)
outliers = curvefit.ensureLogical( outliers, numel( ydata ) );
Error in testfit (line 45)
plot( fitresult{2} ,xData, yData,'LineWidth',10);
it gone when I remove
'LineWidth',10

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

채택된 답변

Voss
Voss 2022년 5월 28일
The function plot from the Curve Fitting Toolbox does not have the same set of options as the function plot from base MATLAB.
To set any property of lines created with Curve Fitting Toolbox plot, you can store the line handle and then set the property after the plot call.
createFits1();
function [fitresult, gof] = createFits1()%x, y)
%% Initialization.
x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6];
%y = [0.001, 0.00111499, 0.0011926, 0.0013699, 0.00161633, 0.00192075, 0.00274991, 0.00357156]; % for 100% 0.64
% x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6]';
% y = [0.001, 0.001161, 0.00141484, 0.0021995, 0.00408401, 0.00454675, 0.0067192, 0.00987622]'; % 10% 0.54 + 90% 0.99
y = [0.001, 0.00117728, 0.00146081, 0.00215119, 0.00307794, 0.00398234, 0.00619084, 0.00696612];
% Initialize arrays to store fits and goodness-of-fit.
fitresult = cell( 10, 1 );
gof = struct( 'sse', cell( 10, 1 ), ...
'rsquare', [], 'dfe', [], 'adjrsquare', [], 'rmse', [] );
%% Fit: 'Mooney (1951)'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( '0.001*(exp((b*x)/(1-x/a)))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0];
opts.StartPoint = [1 1];
opts.Upper = [1 100];
% Fit model to data.
[fitresult{1}, gof(1)] = fit( xData, yData, ft, opts );
plot( fitresult{1}, xData, yData );
legend('y vs. x', 'Mooney (1951)', 'Location', 'NorthEast', 'Interpreter', 'none' );
hold on
%% Fit: 'Krieger and Dougherty (1959)'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( '0.001*(1-x/a)^(-b*a)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0];
opts.StartPoint = [1 1];
opts.Upper = [1 100];
% Fit model to data.
[fitresult{2}, gof(2)] = fit( xData, yData, ft, opts );
h = plot( fitresult{2} ,xData, yData);%,'LineWidth',10);
set(h,'LineWidth',10);
legend('y vs. x', 'Krieger and Dougherty (1959)', 'Location', 'NorthEast', 'Interpreter', 'none' );
hold on
end
  댓글 수: 2
Tesla
Tesla 2022년 5월 28일
Thank you very much it works!
Voss
Voss 2022년 5월 28일
You're welcome!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by