Struggling to connect end points of lines within a plot

7 views (last 30 days)
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])

Accepted Answer

KSSV
KSSV on 11 Mar 2021
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')
  2 Comments
Joshua Tsui
Joshua Tsui on 11 Mar 2021
Thanks for the response KSSV.
Do you know a way I can remove the horizontal line at y=0 ?
KSSV
KSSV on 11 Mar 2021
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(3:end,1) R(3:end,1)]',[L(3:end,2) R(3:end,2)]','g')

Sign in to comment.

More Answers (1)

Joshua Tsui
Joshua Tsui on 12 Mar 2021
AZero=[0]
BZero=[0]
AEven=A(:,2:2:end);
BEven=B(:,2:2:end);
AFull=[AZero,AEven']
BFull=[BZero,BEven']
plot(AFull.',BFull.','g')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!