-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitLine.m
24 lines (22 loc) · 834 Bytes
/
fitLine.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
function [yFit, slope, coefficients] = fitLine(x, y, type)
% [yFit, slope, coefficients] = fitLine(x, y, type)
%
% Function fits a line to the data y given x. It outputs the y-values of
% the curve corresponding to x, as well as the slope of the line. Full set
% of coefficients is contained within the coefficients variable. Currently
% supported types are linear-linear and linear-circular (linear-linear is
% default).
if nargin < 3
type = 'linear-linear';
end
if strcmpi(type, 'linear-linear')
coefficients = polyfit(x, y, 1);
yFit = polyval(coefficients , x);
slope = coefficients(1);
elseif strcmpi(type, 'linear-circular')
coefficients = CircularRegression(x, y);
yFit = coefficients(1).*x + coefficients(2);
slope = coefficients(1);
else
error([type 'is currently not supported']);
end