How to draw horizontal and vertical lines in MATLAB?

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

Leave a Comment