Draw a line between two shapes

and i got a matrix like this
x =
7 1 here i want to draw a line between the blue circle no.1 with the red triangle no.7
1 1 here i want to draw a line between the blue circle no.1 with the red triangle no.1
9 2 here i want to draw a line between the blue circle no.2 with the red triangle no.9
5 2 and so on...
4 3 .
8 3 .
10 4
7 4
6 5
2 5
but i don't know how to do it Thank you! :)

 採用された回答

Image Analyst
Image Analyst 2016 年 3 月 28 日

0 投票

When you plotted the data with plot() or scatter(), you must have had the coordinates. I'll assume they are called xData and yData. And (the poorly named) x is a list of indexes that you want to draw between. So you'd do
hold on;
for row = 1 : size(x, 1)
x1 = xData(x(row, 1));
y1 = yData(x(row, 1));
x2 = xData(x(row, 2));
y2 = yData(x(row, 2));
line([x1, x2], [y1, y2], 'LineWidth', 2, 'Color', 'k');
end

1 件のコメント

Image Analyst
Image Analyst 2016 年 3 月 28 日
I don't care if it's random. The fact is you still have the coordinates or there is no possible way you could have created that plot. So my code will work. If you think you don't have any data, then tell me how you created that plot.

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

その他の回答 (0 件)

カテゴリ

質問済み:

N.
2016 年 3 月 28 日

コメント済み:

2016 年 3 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by