How to do you use a loop in a sub-function to extract values obtained in your main code?

1 回表示 (過去 30 日間)
Monique Embury
Monique Embury 2019 年 4 月 9 日
コメント済み: Geoff Hayes 2019 年 4 月 11 日
I am trying to extract the values from the displacement matrix that correspond to the x and y values that were imported from a text file. Extraction of X and Y work, but the ux and uy matrices remain empty. Can someone help me please?
Thanks in advance.
%
displacement=stiffness\force
%
%plots undeformed and deformed structure
function PlotMeshonMesh(coordinates,nodes,displacement)
nel=length(nodes); %number of elements
nnel=size(nodes,2); %number of nodes per element
nnode=length(coordinates); %number of nodes
%
% empty required matrices
X=zeros(nnel,nel);
Y=zeros(nnel,nel);
ux=zeros(nnel,nel);
uy=zeros(nnel,nel);
scalefactor=10^6;
%
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
for p=1:nnode
ux(i,iel)=displacement(2*p-1,1)*scalefactor %extract x value of the node with displacement
uy(i,iel)=displacement(2*p,1)*scalefactor %extract y value of the node with displacement
end
end
end
hold on;
%Plotting the FEM mesh and profile of the given component
f4 = figure ;
plot(ux,uy,'r')
hold on
plot(X,Y,'k')
hold off
end
  7 件のコメント
Monique Embury
Monique Embury 2019 年 4 月 11 日
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)=displacement(2*nd(i)-1,1)*scalefactor; %extract x value of the node with displacement
uy(i,iel)=displacement(2*nd(i),1)*scalefactor; %extract y value of the node with displacement
uX=X-ux;
uY=Y-uy;
end
end
This is what I did and it worked. Thanks for your suggestions.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by