首页 > 解决方案 > 如何将矩阵的行绘制为图形上的点?

问题描述

我正在尝试绘制一个桁架桥,桥的线条显示存在哪些力,不同的颜色显示压缩和张力。桥的线路由节点连接。我根据力的大小除以 1000 得出线宽。

A = [-0.5 1 0 0 0 0 0 0 0 0.5 0 0 0 0 0; 
-sqrt(3)/2 0 0 0 0 0 0 0 0 -sqrt(3)/2 0 0 0 0 0;
0 -1 1 0 0 0 0 0 0 0 -0.5 0.5 0 0 0; 
0 0 0 0 0 0 0 0 0 0 -sqrt(3)/2 -sqrt(3)/2 0 0 0;
0 0 -1 1 0 0 0 0 0 0 0 0 -0.5 0.5 0; 
0 0 0 0 0 0 0 0 0 0 0 0 -sqrt(3)/2 -sqrt(3)/2 0; 
0 0 0 -1 0.5 0 0 0 0 0 0 0 0 0 -0.5; 
0 0 0 0 -sqrt(3)/2 0 0 0 0 0 0 0 0 0 -sqrt(3)/2; 
0 0 0 0 -0.5 -1 0 0 0 0 0 0 0 0 -0.5; 
0 0 0 0 0 1 -1 0 0 0 0 0 0 -0.5 0.5; 
0 0 0 0 0 0 0 0 0 0 0 0 0 sqrt(3)/2 sqrt(3)/2; 
0 0 0 0 0 0 1 -1 0 0 0 -0.5 0.5 0 0; 
0 0 0 0 0 0 0 0 0 0 0 sqrt(3)/2 sqrt(3)/2 0 0; 
0 0 0 0 0 0 0 1 -1 -0.5 0.5 0 0 0 0; 
0 0 0 0 0 0 0 0 0 sqrt(3)/2 sqrt(3)/2 0 0 0 0];

w7 = 800;
w8 = 900;
w9 = 13000;
W = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; w7; 0; w8; 0; w9];
x = A\W;

nodes = [0 0; 
         0.5 sqrt(3)/2; 
         1.5 sqrt(3)/2; 
         2.5 sqrt(3)/2; 
         3.5 sqrt(3)/2; 
         4 0; 
         3 0; 
         2 0; 
         1 0];
beams = [1 2; 
         2 3; 
         3 4; 
         4 5; 
         5 6; 
         6 7; 
         7 8; 
         8 9; 
         1 9; 
         2 9; 
         3 9; 
         3 8; 
         4 8; 
         4 7; 
         5 7];

clf; % clear the figure window
set(gcf,'position',[20 50 600 250],'paperpositionmode','auto')
hold on
% Code to plot goes here!
axis equal; % make aspect ratio 1:1
axis([-.5 4.5 -.5 1.5]);
for jj = 1:15
    if x(jj,1) > 0
        plot(nodes(beams(jj,1:2),1),nodes(beams(jj,1:2),2),'-g','LineWidth',abs(x(jj,1))/1000);
    else
        plot(nodes(beams(jj,1:2),1),nodes(beams(jj,1:2),2),'-r','LineWidth',abs(x(jj,1))/1000);
    end
end
plot(nodes(1:9,1:2),'.k','MarkerSize',80);
print(gcf,'-dpng','truss_bridge_beams.png');

我按照我想要的方式绘制线条,但我想将节点绘制为我在节点矩阵中指定的行向量处的点。但是,当我尝试这样做时,这些点分散在图表中。有人可以帮我解决这个问题吗?

标签: matlab

解决方案


这是因为 plot(Y) 将 Y 的列与行索引而不是相互绘制。

plot(nodes(1:9,1), nodes(1:9,2))

应该解决问题。


推荐阅读