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! :)

 采纳的回答

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 个评论

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 个)

类别

帮助中心File Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by