【问题标题】:Draw lines between points in Matlab在 Matlab 中的点之间画线
【发布时间】:2023-03-05 12:04:01
【问题描述】:

我有一个文本文件(“coordinates.txt”),其中包含点的 x 和 y 坐标。 文件如下所示:

11 44 2 9

11 44 5 8

2 1 6 11

2 1 10 3

我需要在 (11, 44) 到 (2, 9)、(11, 44) 到 (5, 8)、(2, 1) 到 (6, 11) 和 (2, 1) 之间画线) 到 (10, 3)。

我可以手动做到这一点:

x = [11 11 2 1; 2, 5, 6, 10];

y = [44 44 1 1; 9 8 11 3];

plot (x, y).

但实际文件很长,我需要“自动化”这个过程。

我试过了:

load coordinates.txt;

edit coordinates.txt;

x1= [coordinates(:, 1); coordinates(:, 3)];

y1 = [coordinates(:, 2); coordinates(:, 4)];

plot (x1, y1).

它给了我从 (11, 44) 到 (2, 9), (2, 9) 到 (5, 8), (5, 8) 到 (6, 11), (6, 11) 的线到 (10, 3)。

有人可以帮忙吗?

【问题讨论】:

    标签: matlab text draw lines points


    【解决方案1】:

    假设您将文件正确读取到n-by-4 矩阵coordinates
    绘制

    plot( coordinates(:,[1 3]).', coordinates(:,[2 4]).' );
    

    应该做的伎俩

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      相关资源
      最近更新 更多