Why is an extra line being plotted?
Mostrar comentarios más antiguos
Hello,
I have been trying to display the deflection and displacement of beams within a building. Currently, I am having an issue from within my loop which plots the displacement of each floor.
As you can see from the plot below, I have a red horizontal line from (0,0) to(2,0). Why is this? I think I have done something wrong in my "Displacement" loop but I am not sure

numFlr=2
Phi_EigVec=[1 3;2 -3;]
y1=zeros(numFlr,1);
y2=zeros(numFlr,1);
x1=zeros(numFlr,1);
x2=Phi_EigVec(:,1);
%Displacement
hold on
for i=1:numFlr
y1(i)=i
y2(i)=i
A = [x1(:) x2(:)]; B = [y1(:) y2(:)];
plot(A.',B.','r')
end
%Beam Deflection
AZero=[0]
BZero=[0]
AEven=A(:,2:2:end);
BEven=B(:,2:2:end);
AFull=[AZero,AEven']
BFull=[BZero,BEven']
plot(AFull.',BFull.','g')
%Vertical Line
y=numFlr
line([0,0],[0,y])
%Axis
axis([-5 5 -1 5])
3 comentarios
Adam Danz
el 12 de Mzo. de 2021
Look at your A/B variables and recall that a line will be drawn for each column of inputs.
Joshua Tsui
el 12 de Mzo. de 2021
You just need to move the two commented lines outside of the loop. Alan Stevens's answer does this (though, no need for the 2nd "hold on").
hold on
for i=1:numFlr
y1(i)=i
y2(i)=i
% A = [x1(:) x2(:)]; B = [y1(:) y2(:)];
% plot(A.',B.','r')
end
UPDATE
Actually, you don't need the loop at all,
y1 = 1:numFlr;
y2 = y1;
A = [x1(:) x2(:)]; B = [y1(:) y2(:)];
hold on
plot(A.',B.','r')
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!