circle.m(畫二維圓的函數)
%該函數是畫二維圓圈,輸入圓心坐標和半徑
%rectangle()函數參數‘linewidth’修飾曲線的寬度
%'edgecolor','r',edgecolor表示邊框顏色,r表示顏色參數
%'facecolor','b',facecolor表示內部填充顏色,b表示顏色參數
function [] = circle( x,y,r )
rectangle('Position',[x-r,y-r,2*r,2*r],'Curvature',[1,1],'linewidth',1);
axis equal;
end
draw_arrow.m(畫兩坐標點之間箭頭的函數)
%該函數是畫從一坐標點到另一坐標點的指向箭頭
function draw_arrow(start_point, end_point)
% 從start_point到end_point畫一箭頭
K = 0.05; %箭頭比例系數
theta = pi / 8; %箭頭角度
A1 = [cos(theta), -sin(theta);
sin(theta), cos(theta)]; %旋轉矩陣
theta = -theta;
A2 = [cos(theta), -sin(theta);
sin(theta), cos(theta)]; %旋轉矩陣
arrow = start_point' - end_point';
arrow_1 = A1 * arrow;
arrow_2 = A2 * arrow;
arrow_1 = K * arrow_1 + end_point';
arrow_2 = K * arrow_2 + end_point';
hold on;
grid on;
axis equal;
plot([start_point(1), end_point(1)], [start_point(2), end_point(2)], 'k');
plot([arrow_1(1), end_point(1)], [arrow_1(2), end_point(2)], 'k');
plot([arrow_2(1), end_point(1)], [arrow_2(2), end_point(2)], 'k');
hold off;
read_file.m(主函數)
clear;
close all;
clc;
%importdata 函數允許加載各種數據的不同格式的文件
data=importdata('data.csv'); %讀取csv數據文件
%disp(data); %disp函數:顯示文本或數組
for i=1:75
if i<=7
x=data(i,1);
y=data(i,2);
plot(x,y,'rs'),axis([0 400 0 800]);
hold on;
else
x=data(i,1);
y=data(i,2);
plot(x,y,'g.'),axis([0 400 0 800]);
hold on;
end
end
xlabel('x/km'),ylabel('y/km'); %添加標簽
hold on;
%grid on;%添加網格
circle(data(8,1),data(8,2),70); %調用畫圓圈的函數
circle(data(18,1),data(18,2),70);
circle(data(27,1),data(27,2),70);
circle(data(32,1),data(32,2),70);
circle(data(42,1),data(42,2),70);
circle(data(49,1),data(49,2),70);
circle(data(55,1),data(55,2),70);
circle(data(61,1),data(61,2),70);
circle(data(66,1),data(66,2),70);
circle(data(71,1),data(71,2),70);
draw_arrow([data(55,1), data(55,2)],[data(66,1), data(66,2)]); %調用畫箭頭的函數
draw_arrow([data(3,1), data(3,2)],[data(66,1), data(66,2)]);
axis([-100 400 0 800]);
hold on;
結果為:
data.csv數據如下(位置的坐標):
368,319
264,44
392,220
360,110
392,275
296,242
256,121
264,715
258,719
274,728
264,728
254,728
257,733
260,731
262,733
268,733
270,739
225,605
223,598
210,605
220,610
223,615
209,615
230,620
220,622
205,618
168,538
168,542
164,544
168,545
174,544
210,455
180,455
175,452
170,453
185,460
178,460
190,470
183,473
175,472
180,476
120,400
119,388
112,394
125,410
114,405
116,410
113,416
96,304
88,305
100,312
93,311
86,310
94,315
10,451
11,449
13,450
16,450
12,453
15,455
162,660
161,659
159,659
160,657
164,658
110,561
110,563
110,565
109,567
112,568
105,473
106,471
103,473
107,475
104,477
附加:
plot函數
Matlab提供了一些繪圖選項,用於確定所繪曲線的線型、顏色和數據點標記符號。這些選項如表所示:
參考:
1、matlab詳細繪圖
2、matlab教程
---------------------
作者:Asia-Lee
來源:CSDN
原文:https://blog.csdn.net/asialee_bird/article/details/80286591
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!