# Arrow between several points

조회 수: 45 (최근 30일)
ABCDEFG HIJKLMN 2022년 2월 14일
답변: Matt J 2022년 2월 14일
I want to plot the evolution of a solution on a graph.
I have constructed a vector of x and y coordinates as rows, changing every column (at every iteration).
I would like to plot all the points but add arrows in the midpoint between each solution. Something like this:
Is this possible? Thanks in advance!

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

### 채택된 답변

Matt J 2022년 2월 14일
You can use the annotation() command.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
ABCDEFG HIJKLMN 2022년 2월 14일
I would like to know how to do this automatically, that's what I was asking.
Matt J 2022년 2월 14일
편집: Matt J 2022년 2월 14일
The annotation command will let you draw an arrow between any two specified points. You can use the attached file data2units to convert the data coordinates to the units required by the annotation command, e.g.,
h=plot(2:6,'o'); axis equal
[X,Y]=data2units(gca,h.XData,h.YData);
Xmid=X(1:end-1)/2 + X(2:end)/2;
Ymid=Y(1:end-1)/2 + Y(2:end)/2;
annotation('arrow', [X(1), Xmid(1)],[Y(1), Ymid(1)])
annotation('arrow', [Xmid(1), X(2)],[Ymid(1), Y(2)])
%etc...

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

### 추가 답변 (1개)

Matt J 2022년 2월 14일
It might be easier just to use quiver().
h=plot(2:6,'o'); axis equal
[X,Y]=deal(h.XData, h.YData);
q=(1:0.5:numel(X))';
X=interp1(X(:),q); Y=interp1(Y(:),q);
hold on
quiver(X(1:end-1),Y(1:end-1), diff(X), diff(Y),'off')
hold off

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

### 카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by