How to draw horizontal and vertical lines in MATLAB?

Solution 1:

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);

Solution 2:

2 simple ways:

plot(0:0.001:1, 25);

line('XData', [0 1], 'YData', [25 25]);