How to draw horizontal and vertical lines in MATLAB?

后端 未结 3 2242
我在风中等你
我在风中等你 2020-11-30 16:05

I am currently trying to plot a simple vertical and horizontal lines in MATLAB.

For instance, I would like to plot the line y=245. How would I do that?

相关标签:
3条回答
  • 2020-11-30 16:17

    2 simple ways:

    plot(0:0.001:1, 25);
    
    line('XData', [0 1], 'YData', [25 25]);
    
    0 讨论(0)
  • Since MATLAB R2018b you can use the functions xline and yline:

    >> yline(245);
    
    0 讨论(0)
  • 2020-11-30 16:19

    MATLAB's plotting works on a point-by-point basis from the vectors you give. So to create a horizontal line, you need to varying x while keeping y constant and vice-versa for vertical lines:

    xh = [0,10];
    yh = [245,245]; % constant
    
    xv = [5,5]; % constant
    yv = [0,245*2];
    
    plot(xh,yh,xv,yv);
    
    0 讨论(0)
提交回复
热议问题