-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFit2.m
40 lines (32 loc) · 1.02 KB
/
createFit2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [fitresult, gof] = createFit2(t, v, w)
%CREATEFIT2(T,V,W)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : t
% Y Output: v
% Weights : w
% 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 25-Jan-2017 12:40:13
%% Fit: 'untitled fit 1'.
[xData, yData, weights] = prepareCurveData( t, v, w );
% Set up fittype and options.
ft = fittype( '1-B*exp(-x/L)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.0820712070977259 0.93120138460825];
opts.Weights = weights;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = subplot( fitresult, xData, yData );
legend( h, 'v vs. t with w', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel t
ylabel v
grid on