-
Notifications
You must be signed in to change notification settings - Fork 1
/
mastercode function ver.
61 lines (61 loc) · 1.73 KB
/
mastercode function ver.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function points(x,y,names,m,b,vector,ab)
%x and y should be vectors of equal size containing the data.
%names should be a vector of equal size of x and y containing labels
%If labels are not desired, input 0.
%m and b are the slope and y-int. of the line of best fit.
%vector is the vector of x-axis values to be used for comparison.
%It is most likely the same vector as 'x'
%ab is either 'above' 'below' or 'both'.
%This indicates what points you would like marked:
%above/below line of best fit, or both.
num = numel(vector);
plot(x,y,'ok')
hold on
lsline
A = zeros(1,num);
k = 1;
while k < (num + 1)
A(k) = (m*vector(k) + b);
k = k + 1;
end
p = 1;
while p < (num + 1)
if strcmpi('above',ab) == 1
if y(p) > A(p)
xUp = x(p);
yUp = y(p);
namesUp = names(p);
plot(xUp,yUp,'gx')
labelpoints(xUp,yUp,namesUp,'NW',0.15,1,'Color','g')
hold on
end
p = p + 1;
elseif strcmpi('below',ab) == 1
if y(p) < A(p)
xUp = x(p);
yUp = y(p);
namesUp = names(p);
plot(xUp,yUp,'rx')
labelpoints(xUp,yUp,namesUp,'SE',0.15,1,'Color','r')
hold on
end
p = p + 1;
elseif strcmpi('both',ab) == 1
if y(p) > A(p)
xUp = x(p);
yUp = y(p);
namesUp = names(p);
plot(xUp,yUp,'gx')
labelpoints(xUp,yUp,namesUp,'NW',0.15,1,'Color','g')
hold on
elseif y(p) < A(p)
xUp = x(p);
yUp = y(p);
namesUp = names(p);
plot(xUp,yUp,'rx')
labelpoints(xUp,yUp,namesUp,'SE',0.15,1,'Color','r')
hold on
end
p = p + 1;
end
end