How do you plot two graphs on the same figure with a loop?

1 回表示 (過去 30 日間)
Monique Embury
Monique Embury 2019 年 4 月 4 日
コメント済み: Monique Embury 2019 年 4 月 9 日
I am trying to plot the original mesh versus the deformed mesh on the same plot. I have used this loop to plot the original mesh earlier. I am trying to use it with some additonal code to plot both figures on the same graph. My displacement matrix is in the form of [ux1 uy1 ux2 uy2...etc.]. Currently I can only see one figure and it is green.
Thank you in advance.
%plots undeformed and deformed structure
function PlotMeshonMesh(coordinates,nodes,displacement)
nel = length(nodes); %number of elements
nnode = length(coordinates); %total number of nodes in system
nnel = size(nodes,2); %number of nodes per element
%
% empty required matrices
X = zeros(nnel,nel);
Y = zeros(nnel,nel);
Z = zeros(nnel,nel);
scalefactor=100;
%
for iel=1:nel
for i=1:nnel
nd(i)=nodes(iel,i); %extract connected node for (iel)-th element
X(i,iel)=coordinates(nd(i),1); %extract x value of the node
Y(i,iel)=coordinates(nd(i),2);%extract y value of the node
uX(i,iel)=coordinates(nd(i),1)+displacement(2*nnel-1,1)*scalefactor; %extract x value of the node with displacement
uY(i,iel)=coordinates(nd(i),2)+displacement(2*nnel,1)*scalefactor; %extract y value of the node with displacement
end
end
%Plotting the FEM mesh and profile of the given component
f4 = figure ;
set(f4,'name','Postprocessing','numbertitle','off') ;
plot(X,Y,'k',uX,uY,'g')
end
  4 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 8 日
編集済み: Adam Danz 2019 年 4 月 8 日
Maybe the values of ux and uy (which are shown on the plot in green) are much larger than x and Y (which do not appear on the plot). In other words, maybe X and Y are so tiny that you can't see them. Another possiblity is that they are empty. Yet another possibility is that they are exactly the same as ux and uy so they are plotted under the green lines.
Monique Embury
Monique Embury 2019 年 4 月 9 日
Thank you Adam. It seems as though the loop is not gathering the values calculated from my displacement command earlier.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by