I'm trying to find a way to plot a truss in MATLAB, I can do it by using an adjacency matrix and the gplot function, but its very long winded approach especially if there are a lot of nodes connected to one another. Is there a faster way to do this?
A:
I think gplot is a good function to plot a truss. However, it might be possible to simplify the creation of the adjacency matrix.
For example, if your coordinates
are stored in a n-by-2 array, and there is a strut for every pair of nodes that is separated by less than dMax
, you can create the adjacency matrix like this:
%# create a distance matrix
distMatSquared = coordinates * coordinates'; %' #SO formatting
%# create an adjacency matrix that has a 1 wherever
%# distMatSquared is smaller than dMax^2, and that has 0 everywhere else
adjacencyMatrix = distMatSquared < dMax^2;
%# plot the truss with circles at the nodes
figure,gplot(adjacencyMatrix,coordinates,'-o');
Jonas
2010-05-20 01:22:59
Thks, i need to have a little mess around with your idea to get it to work for my truss, but thks for the reply.
JPC
2010-05-20 10:18:30
A:
If this is a truss in the Mechanics of Materials sense:
http://www.mathworks.com/matlabcentral/fileexchange/2170-mastering-mechanics-1-using-matlab-5
and the supporting book
http://www.amazon.com/Mastering-Mechanics-Using-MATLAB-Materials/dp/0138640343
I wrote some truss visualization and just general strength of material stuff into this.
MatlabDoug
2010-05-20 13:37:06