forked from DeNardoLab/BehaviorDEPOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillline.m
17 lines (16 loc) · 821 Bytes
/
fillline.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function [xx,yy]=fillline(startp,endp,pts)
% take starting, ending point & number of points in between
% make line to connect between 2 coordinates
% shaz (2022). Get points for a line between 2 points (https://www.mathworks.com/matlabcentral/fileexchange/29104-get-points-for-a-line-between-2-points), MATLAB Central File Exchange. Retrieved February 24, 2022.
m=(endp(2)-startp(2))/(endp(1)-startp(1)); %gradient
if m==Inf %vertical line
xx(1:pts)=startp(1);
yy(1:pts)=linspace(startp(2),endp(2),pts);
elseif m==0 %horizontal line
xx(1:pts)=linspace(startp(1),endp(1),pts);
yy(1:pts)=startp(2);
else %if (endp(1)-startp(1))~=0
xx=linspace(startp(1),endp(1),pts);
yy=m*(xx-startp(1))+startp(2);
end
end