matlab - 如何将矩阵的行绘制为图形上的点?
问题描述
我正在尝试绘制一个桁架桥,桥的线条显示存在哪些力,不同的颜色显示压缩和张力。桥的线路由节点连接。我根据力的大小除以 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');
我按照我想要的方式绘制线条,但我想将节点绘制为我在节点矩阵中指定的行向量处的点。但是,当我尝试这样做时,这些点分散在图表中。有人可以帮我解决这个问题吗?
解决方案
这是因为 plot(Y) 将 Y 的列与行索引而不是相互绘制。
plot(nodes(1:9,1), nodes(1:9,2))
应该解决问题。
推荐阅读
- sql - 在视图上创建聚集索引后查询视图仍会产生相同的查询计划
- mysql - 带有别名的 Sequelize 属性似乎未定义
- r - 在 R 中使用 Equamax 旋转复制 SPSS PCA 的结果
- ag-grid - 在 rowData 更新后是否有检测网格何时准备就绪的事件?
- parsing - 移位/减少与歧义语法的冲突
- reactjs - React Hooks:以原子方式更新多个钩子状态
- javascript - Medium-editor:如何应用多个标签包装器?
- reactjs - onMouseEnter 和 onMouseLeave 在我的代码中的行为与预期相反 - 为什么?
- html - HTML5 表单误解了信用卡号的数字字段,如何否决?
- python - Conda:将软件包下载到本地自定义频道