how to make arrows

hi there! here is my question. I am using text command to place some text to specific points [x1,y1]=ginput(1); text(x1,y1,'P'); Now, is it possible to draw an arrow from that point (named P) down to x1 ? Can you please tell me how to do that ? Thanks. PS i don't want to make it manually, it has to be done automatically.

 채택된 답변

Arnaud Miege
Arnaud Miege 2011년 5월 18일

1 개 추천

You can use the annotation function as suggested by Matt. As pointed out, the coordinates need to be normalized. There's a nice utility function on the FEX that does that:
HTH,
Arnaud

추가 답변 (2개)

Matt Fig
Matt Fig 2011년 5월 17일

2 개 추천

As an alternative, here is a way to do it using the ANNOTATION function. Run the code and click where you would like the text to appear (somewhere in the upper middle), then click again near the parabola.
figure('units','norm')
x = -2:.1:2;
axes('units','norm')
plot(x,x.^2); % Plot a parabola
% The first point will have text, second the arrowhead...
[x1,y1] = ginput(2); % Get two points from user.
A = annotation('textarrow','units','norm','string','Parabola');
% Next we need to transform the GINPUT values to figure units.
XL = get(gca,{'xlim','ylim','pos'});
[XL,YL,P] = deal(XL{:});
Ax = P(3)*(x1-XL(1))/diff(XL)+P(1);
Ay = P(4)*(y1-YL(1))/diff(YL)+P(2);
set(A,'x',Ax,'y',Ay) % Set the arrow in the correct position.

댓글 수: 4

Sean de Wolski
Sean de Wolski 2011년 5월 17일
Very nice Matt!
A generalized version of that (perhaps with an inputdlg) would be great for the FEX
Kelly Kearney
Kelly Kearney 2011년 5월 17일
I've written a function that does something similar (takes a line and adds an arrowhead to it), with a little more flexibility for plot aspect ratios. I'll upload it to the FEX.
Matt Fig
Matt Fig 2011년 5월 17일
Good idea Sean de, I will try to get it done in the next day or two.
@Kelly: Right on, I'll look for yours too!
George
George 2011년 5월 18일
Thanks for your reply. But, i have to deal with seismic waves, and zoom in is more than necessery. If you try to zoom in with your script, the function zooms in but the arrow stays where it was before .. i kinda want the arrow to be in the exact same position no matter what.. like if you od it manually and pin it to axes :( i want that but with some code and not manually. Is that possible ? Thanks.

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

카테고리

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

제품

질문:

2011년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by