📄 truss_plot.m
字号:
function truss_plot(bars, nodes, option, nodes2)%% plot a truss.%% input:%% bars integer( m, 2) % The i-th row contains information for bar i in the following form:% [ label-of-lower-left-node label-of-upper-right-node ]%% nodes real( n, 2)% The i-th row contains information for node i in the following form:% [ x-coordinate-of-node y-coordinate-of-node ] %% option integer [optional]% option = 0 bars and nodes are not labeled (default) % option = 1 bars and nodes are not labeled (default)%% nodes2 real( n, 2) [optional]% Second set of node coordinates. The size and format of nodes2 are% the same as those of nodes. If nodes2 contain the coordinates% of the deformed truss, both deformed and undeformed truss can% be displaayed simultaneously.% if( nargin < 2 ) error('bars and nodes must be specified') ;endif( nargin == 2 ) option = 0;end% check if there is a window 'truss_plot'fig = findobj('tag','truss_plot');if length(fig) > 0 % A window 'truss_plot' exists. Activate it for the plots. set(fig,'visible','on'); figure(fig); clf;else % Create a new window 'truss_plot'. fig = figure('Units','normalized',... 'resize','on','tag','truss_plot',... 'name',' Truss ',... 'visible','on');end% get number of bars (m) and number of nodes (n)m = size(bars,1);n = size(nodes,1);% plot the barsfor i = 1:m x = [nodes(bars(i,1),1), nodes(bars(i,2),1)]; y = [nodes(bars(i,1),2), nodes(bars(i,2),2)]; plot(x,y,'b'); hold onend% plot the nodesplot(nodes(:,1),nodes(:,2),'bo'); hold on% enlarge x and y axisxmin = min(nodes(:,1));xmax = max(nodes(:,1));ymin = min(nodes(:,2));ymax = max(nodes(:,2));xscal = max([abs(xmin),abs(xmax)]);yscal = max([abs(ymin),abs(ymax)]);xmin = xmin-0.1*xscal;xmax = xmax+0.1*xscal;ymin = ymin-0.1*yscal;ymax = ymax+0.1*yscal;axis([ xmin xmax ymin ymax ]); axis equal;% label bars and nodes if( option > 0 )% Label the bars for i = 1:m x = [nodes(bars(i,1),1), nodes(bars(i,2),1)]; y = [nodes(bars(i,1),2), nodes(bars(i,2),2)]; h = text(0.45*x(1)+0.55*x(2),0.45*y(1)+0.55*y(2),int2str(i)); set(h,'Color','k','FontSize', 14, 'FontWeight', 'bold'); end% Label the nodes for i = 1:n h = text(nodes(i,1),nodes(i,2),int2str(i)); set(h,'Color','k','FontSize', 14, 'FontWeight', 'bold' ); endendif( nargin > 3 ) % plot the bars for i = 1:m x = [nodes2(bars(i,1),1), nodes2(bars(i,2),1)]; y = [nodes2(bars(i,1),2), nodes2(bars(i,2),2)]; plot(x,y,'r--'); hold on end % plot the nodes plot(nodes2(:,1),nodes2(:,2),'ro'); hold on % enlarge x and y axis xmin2 = min(nodes2(:,1)); xmax2 = max(nodes2(:,1)); ymin2 = min(nodes2(:,2)); ymax2 = max(nodes2(:,2)); xscal2 = max([abs(xmin2),abs(xmax2)]); yscal2 = max([abs(ymin2),abs(ymax2)]); xmin2 = xmin-0.1*xscal; xmax2 = xmax+0.1*xscal; ymin2 = ymin-0.1*yscal; ymax2 = ymax+0.1*yscal; xmin = min([xmin,xmin2]); xmax = max([xmax,xmax2]); ymin = min([ymin,ymin2]); ymax = max([ymax,ymax2]); axis([ xmin xmax ymin ymax ]); axis equal;end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -