how run generated code from apps
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
roberto
am 16 Feb. 2023
Verschoben: Voss
am 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
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 16 Feb. 2023
Bearbeitet: Kevin Holly
am 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)
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fit Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!