Effacer les filtres
Effacer les filtres

Get my X and Y values from curve fitting tool

77 vues (au cours des 30 derniers jours)
Shree Pannaga
Shree Pannaga le 13 Jan 2023
Modifié(e) : Matt J le 13 Jan 2023
First of all i´m completely new on matlab so forgive me if this is a dumb question... I had a curve fitting problem for my project and curve fit was completed using using custom fit equation and got a very nice fit.
The equation used for curve fitting was Y=1-((1-(X)^B)^A). R2 value I got around 95% and the co-effiecent value I got was A =0.6454 (0.5501, 0.7407) and B =0.1164 (0.09036, 0.1425)
Now I need the values of the X axis and Y axis Data of the fitted curve so I wonder if there is a fast and simple way to get them.
Please reply to my question immedieately. Any help will be appriciated.
  2 commentaires
Mathieu NOE
Mathieu NOE le 13 Jan 2023
hello
it would help if you would share your code
Shree Pannaga
Shree Pannaga le 13 Jan 2023
function [fitresult, gof] = createFit(CycleRatio, Damage)
%CREATEFIT(CYCLERATIO,DAMAGE)
% Create a fit.
%
% Data for 'untitled fit 5' fit:
% X Input: CycleRatio
% Y Output: Damage
% 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 13-Jan-2023 20:08:19
%% Fit: 'untitled fit 5'.
[xData, yData] = prepareCurveData( CycleRatio, Damage );
% Set up fittype and options.
ft = fittype( '1-(1-(x)^B)^A', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-1 -1];
opts.StartPoint = [0.779167230102011 0.530797553008973];
opts.Upper = [1 1];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 5' );
h = plot( fitresult, xData, yData );
legend( h, 'Damage vs. CycleRatio', 'untitled fit 5', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'CycleRatio', 'Interpreter', 'none' );
ylabel( 'Damage', 'Interpreter', 'none' );
grid on

Connectez-vous pour commenter.

Réponses (1)

Cameron
Cameron le 13 Jan 2023
Modifié(e) : Cameron le 13 Jan 2023
If you are using the Curve Fitting App, go to Export in the top right and select Export to Workspace. Then select OK, and your information should be in the fittedmodel variable.
fittedmodel.p1
fittedmodel.p2
%or
fittedmodel.A
fittedmodel.B
  2 commentaires
Shree Pannaga
Shree Pannaga le 13 Jan 2023
Hello Mr. Cameron, Thank you for the answer. But in my problem I am getting the variable values A and B oncee the fitting is created. My problem is I want to get the values of X axis and Y axis data after I finishes the fitting.
Matt J
Matt J le 13 Jan 2023
Modifié(e) : Matt J le 13 Jan 2023
The fitting process does not generate any X,Y data post-fit. However, the fittedmodel object that you export can be used to evaluate the fitted curve at any X values you wish. For example, if xdata,ydata are the data that you used to perform the fit, then you could do,
X=linspace(min(xdata), max(xdata),1000);
Y=fittedmodel(X)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by