Plot multi curve in one figure
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!