Matlab drawing connection, arrow representation

Matlab drawing connection, arrow representation


The purpose of writing this article is that when the author is visualizing related problems in Matlab, he will mark the connections between points and search for related implementation methods on the Internet. The result is that a lot of code needs to be paid for, or some bloggers and book authors did not make clear the definition of the function, etc., which made it impossible to implement. So I explored it myself, encapsulated some main steps into functions, and summarized some small details. I think this summary is meaningful and can help readers with related needs.

  接下来给的函数是给定指定的点集,按照顺序连接各店并形成回路,读者也可以对函数进行改进,不封装成函数
  也行,笔者把实现的大体思路给读者,哈哈哈。

Mainly the use of line function, text function, and finally the author recommends the arrow representation method
line([x1,x2],[y1,y2]), x1x2y1y2 is the horizontal and vertical coordinates corresponding to the connecting point.
text(x1,y1,'***'), x1y1 is the coordinate to add the note, and *** is the content of the note.

The use of arrow diagrams can be achieved with quiver and annotation. Here the author Amway has an arrow chart blog, which is well written:
arrow chart
The following is the code implemented by the author in Matlab:

position = [5 6
    9 8
    3 1
    2 4
    7 10];
s = randperm(5);
drawpath(s,position);

function drawpath(s,position)
% 画出路线
% s为路径,position为各点坐标

s1 = [s s(1)];      % 闭合回路
figure
hold on
plot(position(:,1),position(:,2),'o')
plot(position(1,1),position(1,2),'rv','MarkerSize',20)
for i = 1:size(position,1)
    text(position(i,1)+0.05,position(i,2)+0.05,num2str(i));
end
A = position(s1,:);
row = size(A,1);  % 获得A的行的值
for i = 1:size(position,1)
    line([A(i,1),A(i+1,1)],[A(i,2),A(i+1,2)]);
end
xlabel('x轴')
ylabel('y轴')
title('路线图')

Insert picture description here

Guess you like

Origin blog.csdn.net/wlfyok/article/details/107950129