如何在MATLAB中绘制6x6网格上的三角形? [英] How to plot triangles on a 6x6 grid in MATLAB?

查看:677
本文介绍了如何在MATLAB中绘制6x6网格上的三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 a.txt 这样的文件:

  0 0 0 3 4 3 
0 0 3 0 3 4
0 1 0 4 4 4
0 1 3 1 3 5
0 2 0 5 4 5
0 3 0 0 4 0

这些是三角形的顶点[x1 y1 x2 y2 x3 y3] 6x6网格。
我需要在一张图上看到这些三角形。



这怎么能在MATLAB中完成?



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
感谢所有人!

终于发生了什么:

  a = dlmread('a.txt'); 
$ b clf
xlim([0 6])
ylim([0 6])
for i = 1:size(a,1)

line(a(i,[1:2:5,1]),a(i,[2:2:6,2]),'color',rand(1,3))
暂停;

结束
格;


解决方案

  a = dlmread('a.txt')
clf

for i = 1:size(a,1)
line(a(i,[1:2:5,1 ]),a(i,[2:2:6,2]),'color',rand(1,3))
end

请注意,我正在重复顶点以完成三角形,并且每次循环都使用随机颜色。



因为格式很简单,所以我可以使用默认的DLMREAD。


I have a file a.txt which is like:

0 0 0 3 4 3
0 0 3 0 3 4
0 1 0 4 4 4
0 1 3 1 3 5
0 2 0 5 4 5
0 3 0 0 4 0

These are vertices of triangles [x1 y1 x2 y2 x3 y3] that I need to plot on a 6x6 grid. I need to see these triangles on a single graph.

How can this be done in MATLAB?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ thanks a lot everyone!

finally what worked:

a = dlmread('a.txt');

clf
xlim([0 6])
ylim([0 6])
for i = 1:size(a,1)

   line(a(i,[1:2:5,1]), a(i,[2:2:6,2]), 'color',rand(1,3))
   pause;

end
grid on;

解决方案

a = dlmread('a.txt')
clf

for i = 1:size(a,1)
    line(a(i,[1:2:5,1]), a(i,[2:2:6,2]), 'color',rand(1,3))
end

Notice that I am repeating the vertice to complete the triangle and the I am using a random color each time through the loop.

Because the format is easy, I can use DLMREAD with defaults.

这篇关于如何在MATLAB中绘制6x6网格上的三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆