connect lines on scatter plot showing arrows

Hi,
I am plotting 2 scatter plots on the same figure with corresponding points. I would like to connect each pair of points with an arrow towards the second. Here is my code so far
figure; scatter(xpre,ypre,'filled','SizeData',100,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[.4940 .1840 .5560]);hold on;scatter(xpost,ypost,'filled','SizeData',100,'MarkerEdgeColor',[.9290 .6940 .1250],'MarkerFaceColor',[.9290 .6940 .1250]);hold on
for i = 1:22
plot([xpre(i,:) xpost(i,:)],[ypre(i,:) ypost(i,:)],'-->','Color',[0 0 0],'LineWidth',2);
end
However I get the attached figure. Grateful for any assistance. Thank you!

 採用された回答

Bruno Luong
Bruno Luong 2022 年 4 月 21 日
編集済み: Bruno Luong 2022 年 4 月 21 日

0 投票

Try this
quiver(xpre, ypre, xpost-xpre, ypost-ypre, 'off')

7 件のコメント

bsriv
bsriv 2022 年 4 月 21 日
Thanks- I'm getting this error
Error using quiver (line 44)
Uneven parameter-value pairs.
Not sure why... Thanks
Bruno Luong
Bruno Luong 2022 年 4 月 21 日
You might have an older MATLAB, replace 'off' with 0, or ..., 'AutoScale', 'off'). In any case check the doc of your quiver command.
bsriv
bsriv 2022 年 4 月 21 日
Thanks- it works but i can't reshape the arrows/arrowheads. It's not really clear from the documentation how do I narrow the arrowheads and make them so they don't overlap with the points?
Bruno Luong
Bruno Luong 2022 年 4 月 21 日
Make thr arrow 10% shorter
quiver(xpre, ypre, 0.9*(xpost-xpre), 0.9*(ypost-ypre), 'Autoscale', 'off')
bsriv
bsriv 2022 年 4 月 21 日
Thanks- but I can't figure out how to reshape the arrowheads themselves (i.e., make them smaller )
Bruno Luong
Bruno Luong 2022 年 4 月 21 日
編集済み: Bruno Luong 2022 年 4 月 21 日
This is beyond the question you ask, but I'll be nice to do somethibg you could figure out on your own that there is somethig call 'MaxHeadSize'
bsriv
bsriv 2022 年 4 月 21 日
thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

製品

リリース

R2019b

質問済み:

2022 年 4 月 21 日

コメント済み:

2022 年 4 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by