how run generated code from apps

2 次查看(过去 30 天)
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

采纳的回答

Kevin Holly
Kevin Holly 2023-2-16
编辑:Kevin Holly 2023-2-16
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 个评论
roberto
roberto 2023-2-16
移动:Voss 2023-2-16
Tks very much
Kevin Holly
Kevin Holly 2023-2-16
Please accept the answer if this satisfies your questions. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by