rectangle to draw a line

Hi, I'm using rectangle to draw a circle then a line in a for loop. However, when I draw the second line, after drawing the circle, the line width is slimmer than the previous drawn line and even the next drawn lines.
I'm confuzed. I saved the handle and looked at the first created line and compared it to the second line. However, they are identical. Any advice?
Thank you
for m=1:10
rectangle('parent',handles.Axes9,'Position',[x,y,30,30],'Curvature',...
[1,1],'FaceColor',color);
rectangle('parent',handles.Axes9,'Position',...
x+14,y+30,1,h],'FaceColor','black');
text(x+8,y+15, {m},'fontsize',14,'color','black',...
'fontweight','bold','parent',handles.Axes9);
end

답변 (2개)

Image Analyst
Image Analyst 2013년 1월 14일

0 개 추천

You probably need to use "hold on" in between those calls. But why not use line() or plot() to create a line? Why use rectangle to create a line?

댓글 수: 5

Vincent I
Vincent I 2013년 1월 14일
The reason why is because I already use a plot and lines. Its easier for me to use delete(findobj(handles.Axes9,'Type','Text')) and delete(findobj(handles.Axes9,'Type','Rectangle')) than to keep a track of all of them.
Hold on and off did not work...
Image Analyst
Image Analyst 2013년 1월 14일
If you used hold on then you would not have the same handle number for both lines. Because you said you do have the same number I think that the second line blew away the first one and reused the same handle number. Anyway, we can't run your code to test it.
Vincent I
Vincent I 2013년 1월 15일
편집: Jan 2013년 1월 15일
when I said "they are identical" i didnt mean the handle number is the same. What I meant is that the handle is identical except the handle number. If
Below is a smiplified version of my code that shows the issue that I'm having:
handles.Axes9=axes;
set(handles.Axes9,'xlim',[0 800],'ylim',[0 300])
color='green';
for a=1:6
switch a
case 1
x = 20; y = 10; h = 125;
case 2
x = 60; y = 10; h = 120;
case 3
x = 170; y = 10; h = 135;
case 4
x = 325; y = 10; h = 120;
case 5
x = 540; y = 10; h = 130;
case 6
x = 570; y = 10; h = 130;
end
rectangle('parent',handles.Axes9,'Position', [x,y,30,30],'Curvature',[1,1],'FaceColor',color);
rectangle('parent',handles.Axes9,'Position',[x+14,y+30,1,h],'FaceColor','black');
text(x+8,y+15,{a},'fontsize',14,'color','black','fontweight','bold','parent',handles.Axes9);
end
thank you
Jan
Jan 2013년 1월 15일
Do you mean: "that the line is identical except for the handle number"?
Vincent I
Vincent I 2013년 1월 15일
편집: Vincent I 2013년 1월 15일
:-) yes. the rectangle "line" is identical except the handle number

댓글을 달려면 로그인하십시오.

Jan
Jan 2013년 1월 15일

0 개 추천

This has been a useful example.
The code is correct and the display of the graphics is correct also. You see the effect, that rectangle draws to rounded pixel positions. And sometimes they are nearer to each other, such that the line looks smaller. When you resize the figure, you will see, that other lines are concerned.

댓글 수: 5

Vincent I
Vincent I 2013년 1월 15일
편집: Vincent I 2013년 1월 15일
so, i'll take it there's no way around this?
it is strange because in the code provided the first two lines are slimer than the rest. In my code the second line is the only one thats slim(see below).
Vincent I
Vincent I 2013년 1월 15일
편집: Vincent I 2013년 1월 15일
ok so I think I might have found a way to get away from drawing the rectangle line and then delete it easily.
delete(findobj(findobj(0,'tag','Axes9'),'type','line'))
or
delete(findobj(findobj(0,'tag','Axes9'),'type','line'),'-or','type','rectangle'))
I think one of the reasons why I liked using rectangle is because Axes9 were the only axes that I was using rectangle. It was easy just to look at the main figure for rectangles and detele them. However since I've just figure it out how to delete all the lines from the Axes9.
yes I know I could just use delete(handles.Axes9...). However I'm trying to delete the lines/rectangle from a different *.m file
Thank you for your help
Image Analyst
Image Analyst 2013년 1월 15일
I'm not sure if you still have a question or not.
fixed my issue by doing the following:
rectangle('parent',findobj(0,'Tag','Axes9'),'Position', [x,y,30,30],'Curvature',[1,1],'FaceColor',color);
line([x+15 x+15],[y+30 y+h],'LineWidth',2,'Color','Black','parent',findobj(0,'Tag','Axes9'))
and deleting everything with:
delete(findobj(findobj(0,'tag','Axes9'),'Type','Text','-or','type','rectangle','-or','type','line'))
Thank you for all your help

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

2013년 1월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by