% Worshop Example 4 (WorkshopEx04.m) % % This script evaluates a file that specifies a truss. % It does this by defining the following two matrices % % nodes - an nn-by-2 matrix with one row per node, where % each row specifies the (x,y) coordinates of the % corresponding node % % bars - an nb-by-2 matrix with one row per bar, where % each row specifies the indices of the source and % target nodes for the corresponding bar. % % The script then plots the specified truss % Daniel D. Warner % July 9, 2008 name = input('Enter the name of the file defining the truss: ','s'); eval(name) % Plot the nodes as black cicles [nn,two] = size(nodes); xn = nodes(:,1); yn = nodes(:,2); plot(xn,yn,'ok') title(name) % Set the view, include a small margin around the truss xmargin = 0.1*max(abs(xn)); ymargin = 0.1*max(abs(yn)); xmin = min(xn) - xmargin; xmax = max(xn) + xmargin; ymin = min(yn) - ymargin; ymax = max(yn) + ymargin; axis([xmin xmax ymin ymax]); % Plot the bars hold on [nb,two] = size(bars); for k=1:nb % Get the index for the first node (source node) of bar k sindx = bars(k,1); % Get the index for the second node (target node) of bar k tindx = bars(k,2); plot([xn(sindx) xn(tindx)],[yn(sindx) yn(tindx)]) end % label the nodes xoffset = xmargin/4; yoffset = ymargin/4; for k=1:nn text(xn(k)+xoffset, yn(k)+yoffset, num2str(k)) end hold off