how run generated code from apps

2 views (last 30 days)
roberto
roberto on 16 Feb 2023
Moved: Voss on 16 Feb 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

Accepted Answer

Kevin Holly
Kevin Holly on 16 Feb 2023
Edited: Kevin Holly on 16 Feb 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 Comments
roberto
roberto on 16 Feb 2023
Moved: Voss on 16 Feb 2023
Tks very much
Kevin Holly
Kevin Holly on 16 Feb 2023
Please accept the answer if this satisfies your questions. Thanks.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!