如何在MATLAB中在6x6网格上绘制三角形?

如何在MATLAB中在6x6网格上绘制三角形?,matlab,graph,geometry,Matlab,Graph,Geometry,我有一个文件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.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');

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;
请注意,我正在重复垂直以完成三角形,并且每次在循环中使用随机颜色

由于格式很简单,我可以使用带有默认值的DLMREAD。

您可以使用该函数来完成此操作,尽管您指定的许多三角形都是重叠的:

a = [0 0 0 3 4 3; ...  % A variable "a" containing the data from the file
     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];
x = a(:,[1 3 5])';  % Get the x coordinates, one set per column
y = a(:,[2 4 6])';  % Get the y coordinates, one set per column
patch(x,y,'r');     % Use patch to plot one triangle per column, colored red

我还在寻找。在matlab中找不到任何三角形函数。。。还有一个问题是,图形在接近最高值时会自动截断,如何将其固定在6x6?自动设置限制确实值得提出自己的问题。最好将这些问题集中起来。(使用XLIM和YLIM会有帮助!)谢谢@MatlabDoug,在向图像添加三角形后,我如何使它暂停按键?我拥有的大部分三角形都是重叠的,所以patch()将不会那么有用,除非它能逐个显示三角形,比如说在暂停按键后?也许添加第三个维度可能会有所帮助:patch(x,y,repmat(1:size(a,1),3,1),'r');视图(3)
a = [0 0 0 3 4 3; ...  % A variable "a" containing the data from the file
     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];
x = a(:,[1 3 5])';  % Get the x coordinates, one set per column
y = a(:,[2 4 6])';  % Get the y coordinates, one set per column
patch(x,y,'r');     % Use patch to plot one triangle per column, colored red