Arrow between several points
34 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/893795/image.png)
Is this possible? Thanks in advance!
0 个评论
采纳的回答
Matt J
2022-2-14
You can use the annotation() command.
4 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!