Plot multi curve in one figure
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
