Effacer les filtres
Effacer les filtres

How to apply fit-function on variable

5 vues (au cours des 30 derniers jours)
Niklas Kurz
Niklas Kurz le 20 Juin 2020
Commenté : Niklas Kurz le 16 Juil 2020
So I've got a fit done with cftool:
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( N, A );
% Set up fittype and options.
ft = fittype( 'poly6' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'A vs. N', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'N', 'Interpreter', 'none' );
ylabel( 'A', 'Interpreter', 'none' );
grid on
hold on
Now I want the fit-function to be applid on a variable, let's say y. Hence fit-function(y). For example if the fit-function would go like fit = m*x +n, I'd like to reform it to fit = m*y + n. Thanks in advance and appologies for the 3th question asked in such a short period of time.

Réponse acceptée

Aditya Patil
Aditya Patil le 16 Juil 2020
You can pass the new data to the fitobject. See the example below,
x = sin(1:10)';
x2 = cos(1:10)';
y = (1:10)';
curve = fit(x, y, 'poly2');
y2 = curve(x2);
Here y2 is calculated from the function fit on x.
  1 commentaire
Niklas Kurz
Niklas Kurz le 16 Juil 2020
Thank you. I asked this question in a state of total inexperience. After dealing with Matlab daily its beauty is being more and more revealed.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by