필터 지우기
필터 지우기

put length "ginput" above the line

조회 수: 2 (최근 30일)
Rahma Yeni
Rahma Yeni 2012년 4월 20일
Hello... I want to illustrate my question by a picture like this http://www.flickr.com/photos/rye_ni/7095315251/. I make the line using "ginput", and i get length of the line by this code..
% Initially, the list of points is empty.
xy = [];
n = 0;
% disp('Left mouse button picks points.')
% disp('Right mouse button picks last point.')
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'rx','LineWidth',2)
n = n+1;
xy(:,n) = [xi;yi];
end
% Plot the interpolated curve.
plot(xy(1,:),xy(2,:),'m-','LineWidth',2);
% ---------------------------
pjgAsli = sum(sqrt(diff(xy(1,:)).^2 + diff(xy(2,:)).^2));
the length of the line is "pjgAsli".. How i can put this value above the line..?? Thank you.. ^^

채택된 답변

Jakob Sørensen
Jakob Sørensen 2012년 4월 20일
% Aquire locations
dX = -10; % Text horizontal offset, change to adjust
dY = 10; % Text height offset, change to adjust
xLocation = mean([xy(1,1) xy(1,2)]);
yLocation = mean([xy(2,1) xy(2,2)])+dY;
% Make a text string, change unit, to desired unit
textString = sprintf('%2.2f units',pjgAsli);
% Write text to figure*
th = text(xLocation, yLocation, textString);
  • The 'th' part is to easily acces the text later. It's not strictly needed.
  댓글 수: 2
Rahma Yeni
Rahma Yeni 2012년 4월 20일
Thank you Jakob..
I can implement it to my project.. ^^
Rahma Yeni
Rahma Yeni 2012년 4월 20일
once more again Jakob.. ^^
is possible to change the color and size of the font..??

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

추가 답변 (1개)

Jakob Sørensen
Jakob Sørensen 2012년 4월 20일
You can adjust the properties either at creation...
text(xLocation, yLocation, 'textString', 'Color', 'Red', ...
'FontSize',20);
Or at an existing text...
set(th, 'Color', 'Red', ...
'FontSize',20);
There is also one for font style, but I can't really remember that. You should be able to find that with Google though.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by