I suggest you to use parametric equation of line..
%%figure 1
% mesh a line
N = 50 ;
t = linspace(0,1,N) ;
p0 = [0 0] ; % first point of line
p1 = [5 0] ; % second point of line
% Paremtric equaiton of line
x = p0(1)+(p1(1)-p0(1))*t ;
y = p0(2)+(p1(2)-p0(2))*t ;
figure ;plot(x,y,'.-r')
%%Figure 2
% coordinates of the corner points
p0 = [0 0] ;
p1 = [3 0] ;
p2 = [6 0] ;
p3 = [9 0] ;
p4 = [3 1] ;
p5 = [6 1] ;
% line 1
x1 = p0(1)+(p1(1)-p0(1))*t ;
y1 = p0(2)+(p1(2)-p0(2))*t ;
% line 2
x2 = p1(1)+(p2(1)-p1(1))*t ;
y2 = p1(2)+(p2(2)-p1(2))*t ;
% line 3
x3 = p2(1)+(p3(1)-p2(1))*t ;
y3 = p2(2)+(p3(2)-p2(2))*t ;
% line 4
x4 = p1(1)+(p4(1)-p1(1))*t ;
y4 = p1(2)+(p4(2)-p1(2))*t ;
% line 5
x5 = p2(1)+(p5(1)-p2(1))*t ;
y5 = p2(2)+(p5(2)-p2(2))*t ;
% line 6
x6 = p4(1)+(p5(1)-p4(1))*t ;
y6 = p4(2)+(p5(2)-p4(2))*t ;
%
figure
plot(x1,y1,'.-r') ; hold on
plot(x2,y2,'.-r')
plot(x3,y3,'.-r')
plot(x4,y4,'.-r')
plot(x5,y5,'.-r')
plot(x6,y6,'.-r')