代码之家  ›  专栏  ›  技术社区  ›  CroCo

如何仅在离散数据上绘制直线

  •  1
  • CroCo  · 技术社区  · 9 年前

    我有离散数据,我想通过直线连接它们。例如

    x = 0:0.2:1;
    y = 0:0.2:1;
    plot(x,y, 'LineWidth', 2)
    grid
    

    enter image description here

    预期结果是:

    enter image description here

    是否有实现上述画面的命令?

    1 回复  |  直到 6 年前
        1
  •  2
  •   NKN    9 年前

    你可以用 arrayfun 重复 plot 对于每两组:

    x = 0:0.2:1;
    y = 0:0.2:1;
    figure;hold on;
    plot(x,y, '-o','LineWidth', 2);
    arrayfun(@(xx,yy)plot([xx xx],[0 yy],'r'),x,y)
    arrayfun(@(xx,yy)plot([0 xx],[yy yy],'r'),x,y)
    grid on;
    

    enter image description here