MATLAB: Struggling to connect end points of lines within a plot

connectlinesplot

Hello,
I am having issues creating the following plot:
So far, I have been able to create the F shape but I have run into a few issues:
1) A horizontal line is plotted at floor zero. I am not sure what I have done to make this happen.
2) I am struggling to create the dashed lines which connect the horizontal lines as I am unsure how to extract these values and connect them to (0,0).
Here is my code so far:
numFlr=2
Phi_EigVec=[1 3;2 -3;]
y1=zeros(numFlr,1);
y2=zeros(numFlr,1);
x1=zeros(numFlr,1);
x2=Phi_EigVec(:,1);
hold on
xline(0)
for i=1:numFlr,
y1(i)=i
y2(i)=i
A = [x1(:) x2(:)]; B = [y1(:) y2(:)];
plot(A.',B.','LineWidth', 0.75)
end
axis([-5 5 -1 5])

Best Answer

L = [0 -1; 0 0 ; 0 1 ; 0 2 ] ;
R = [0 -1; 2 0 ;1 1 ; 2 2] ;
plot(L(:,1),L(:,2),'r')
hold on
plot(R(:,1),R(:,2),'r')
plot([L(:,1) R(:,1)]',[L(:,2) R(:,2)]','g')