[英]draw vertical lines at regular intervals in a rectangle in matlab
I need to draw vertical lines at regular intervals in a rectangular box. 我需要在矩形框中以规则的间隔绘制垂直线。 this is what i have used so far:
这是我到目前为止使用的:
xmin=000;
xmax=70000;
ymin=0;
ymax=1000;
line1Val=900;
line2Val=600;
line3Val=300;
xlim([xmin xmax])
ylim([ymin ymax])
xl=get(gca,'XLim');
line(xl,[line1Val line1Val],'Color','y');
line(xl,[line2Val line2Val],'Color','y');
line(xl,[line3Val line3Val],'Color','y');
hold on ;
rectangle('Position',[120000,900,(280000-120000),37],'faceColor','k')
so the width of the rectangle is 160000 units i want to divide this into 4 , where the vertical line is of a different color(say red) and the height of the line is 37 units. 所以矩形的宽度是160000个单位,我想将其分成4个,其中垂直线是不同的颜色(例如红色),线的高度是37个单位。
any ideas on how i can draw this without drawing 4 rectangles whose edges are red and are filled with black color. 关于如何在不绘制4个矩形为红色且用黑色填充的矩形的情况下进行绘制的任何想法。
You could use the parameters xstart
, ystart
, width
and height
for drawing your rectangle: 您可以使用参数
xstart
, ystart
, width
和height
来绘制矩形:
rectangle('Position',[xstart,ystart,width,height],'faceColor','k');
After that, you could determine the line positions in a loop and simply draw these lines: 之后,您可以确定循环中的线位置并只需绘制以下线:
for i = 1:3
x = xstart+i*width/4;
line([x x],[ystart ystart+height],'Color','r');
end
If you want a red line at the start and end of the rectangle, let i = 0:4
. 如果要在矩形的起点和终点处有一条红线,则让
i = 0:4
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.