Is there any way to output coordinates of a point?

11 Ansichten (letzte 30 Tage)
Megan Urbaniak
Megan Urbaniak am 5 Mai 2020
I have a graph of a beam's deflection. I want to output the coordinates of the rightmost bottom point of the deflected beam.
I don't need to have the cordinates displayed on the graph, rather an output in the command window. I know that the coordinates are (16,-0.2079) from using the cursor on the graph.
Here's a photo of the graph:
And my code if interested:
clear;
nnode=4; %nodes per element
%MaxNgaus=3; %max number of Gauss points
% geometric parameters
L=16.0;
c=2.0;
xl=0.0;
xr=L;
yl=0.0;
yr=c;
h=2*c;
Inertia=h^3/12;
%'Input number of elements in X and Y directions:'
numelex=8;
%input('numelex=');
numeley=4;
%input('numeley=');
% materials parameters
YoungModule=1.e7;
PossionRatio=0.3;
% load parameters
Q_force=-1.0e4;
% create the mesh for the beam
[coord,numnod,numele,node,tnd,bnd,lnd,rnd]=beammsh4(xl,xr,numelex,yl,yr,numeley);
% x and y nodal coordinates
x=coord(1,:);
y=coord(2,:);
ndof=2; %number of dimensions of freedom per node
numeqns=numnod*ndof; %number of dimensions of freedom for the whole system
% external force
force=zeros(1,numeqns);
% compute nodal forces due to tractions on the surfaces
force=traction(nnode,lnd,rnd,Inertia,L,c,Q_force,y);
% displacement boundary condition
ifix=[zeros(2,numnod)];
ifix(:,1)=1;
ifix(1,lnd(length(lnd)))=1;
ifix(1,bnd)=1;
young=YoungModule*ones(1,numele);
pr=PossionRatio*ones(1,numele);
% zero bigk matrix to prepare for assembly
bigk=zeros(numeqns,numeqns);
% vector of Gauss points
gauss=[-1.0/sqrt(3), 1.0/sqrt(3)];
%ngaus=3; % the order of Gauss Quadrature for 9-node element
%----------------------------------------------
% start loop over the elements
%----------------------------------------------
for e=1:numele
% compute elemental stiffness matrix
[ke] = elem4(node,x,y,gauss,young,pr,e);
n1=ndof-1;
nlink = 4;
% assemble ke into bigk (global stiffness matrix)
for i=1:nlink;
for j=1:nlink;
if ( (node(i,e) ~= 0 ) & (node(j,e) ~= 0) )
rbk=ndof*(node(i,e)-1)+1;
cbk=ndof*(node(j,e)-1)+1;
re=ndof*(i-1)+1;
ce=ndof*(j-1)+1;
bigk(rbk:rbk+n1,cbk:cbk+n1)=...
bigk(rbk:rbk+n1,cbk:cbk+n1)+ke(re:re+n1,ce:ce+n1);
end % endif
end % endfor j
end % endfor i
end % endfor e
%----------------------------------------------
% end loop over the elements
%----------------------------------------------
% enforce constraints (boundary conditions)
for n=1:numnod
for j=1:ndof
if (ifix(j,n) == 1)
m=ndof*(n-1)+j;
bigk(m,:)=zeros(1,numeqns);
bigk(:,m)=zeros(numeqns,1);
bigk(m,m)=1.0;
force(m)=0;
end
end
end
% solve the stiffness equations (find nodal displacements)
disp=force/bigk;
% display the mesh for the original and deformed configurations
dispplot; % plots figures 1,2
% display the comparison of exact & FEM displ solns of the middle surface
xx=[xl:(xr-xl)/100:xr];
xbar=L-xx;
ExactDispCoordX=xx;
v=PossionRatio;
u2=xbar.^3 - L^3 -((4+5*v)*c*c + 3*L^2)*(xbar-L);
ExactDispY=Q_force/(6*YoungModule*Inertia)*u2;
figure; %figure 3
plot(x(bnd),disp(2.*bnd),'-',ExactDispCoordX,ExactDispY,'-.');
title(['Comparison of Exact and FEM Displ Solns--mesh=',int2str(numelex),'*',int2str(numeley)]);
legend('FEM Soln','Exact Soln');
xlabel('X');
ylabel('Displacement Component --- Uy');
Thank you! :)
  2 Kommentare
Ameer Hamza
Ameer Hamza am 5 Mai 2020
Why not use min() function on the vector of y-values.
Megan Urbaniak
Megan Urbaniak am 5 Mai 2020
Thanks, this works

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sindar
Sindar am 5 Mai 2020
If you want to get the data for an arbirtrary point in your graph, you can add a datatip by clicking with the cursor, then right clicking on the datatip, selecting "Export Cursor Data to Workspace". Look at the Position property of the resulting variable
  2 Kommentare
Megan Urbaniak
Megan Urbaniak am 5 Mai 2020
That works, however I'd prefer a line of code that does this automatically when the program is ran
Sindar
Sindar am 5 Mai 2020
This answer works if you can't describe the point in other way than identifying it on the plot. In your case, Ameer is probably right that "min() function on the vector of y-values" will work here

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by