how run generated code from apps

2 vues (au cours des 30 derniers jours)
roberto
roberto le 16 Fév 2023
Déplacé(e) : Voss le 16 Fév 2023
hello everybody
I've generated a simple code from curve fitting app by export code toolbar.
I've tried to past it in command windows but doesn't work.
function [fitresult, gof] = createFit(close)
%CREATEFIT(CLOSE)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% Y Output: close from eurusd
% 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 16-Feb-2023 15:06:52
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( [], close );
% Set up fittype and options.
ft = fittype( 'poly1' );
% 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, 'close', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
ylabel( 'close', 'Interpreter', 'none' );
grid on

Réponse acceptée

Kevin Holly
Kevin Holly le 16 Fév 2023
Modifié(e) : Kevin Holly le 16 Fév 2023
You would want to save the code as a .m file. Then you can call the function with this line:
createFit(close)
Where close is your input
For example:
data = rand(14,1);
createFit(data)
ans =
Linear model Poly1: ans(x) = p1*x + p2 Coefficients (with 95% confidence bounds): p1 = 0.01584 (-0.02285, 0.05453) p2 = 0.4963 (0.1669, 0.8258)
function [fitresult, gof] = createFit(close)
%CREATEFIT(CLOSE)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% Y Output: close from eurusd
% 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 16-Feb-2023 15:06:52
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( [], close );
% Set up fittype and options.
ft = fittype( 'poly1' );
% 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, 'close', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
ylabel( 'close', 'Interpreter', 'none' );
grid on
end
  2 commentaires
roberto
roberto le 16 Fév 2023
Déplacé(e) : Voss le 16 Fév 2023
Tks very much
Kevin Holly
Kevin Holly le 16 Fév 2023
Please accept the answer if this satisfies your questions. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by