如何从excel中检索坐标并根据地图绘制点? - MATLAB
Posted
技术标签:
【中文标题】如何从excel中检索坐标并根据地图绘制点? - MATLAB【英文标题】:How can I retrieve the coordinate from excel and plot the points according to the map? - MATLAB 【发布时间】:2012-04-18 07:55:49 【问题描述】:我目前正在研究人行道的地图路线系统,但不确定以前是否有人这样做过。但是我已经使用谷歌地球收集了路径的各种路点坐标。
以下数据是路径的坐标点,将其保存在Excel中并导入Matlab
1 1.37723400000000 103.839645000000
2 1.37722000000000 103.839741000000
3 1.37723300000000 103.839843000000
4 1.37723600000000 103.839968000000
5 1.37724100000000 103.840125000000
6 1.37723900000000 103.840245000000
7 1.37724900000000 103.840435000000
8 1.37725700000000 103.840674000000
9 1.37724800000000 103.840896000000
10 1.37726500000000 103.841071000000
11 1.37728300000000 103.841190000000
12 1.37729500000000 103.841393000000
13 1.37734600000000 103.841591000000
14 1.37736500000000 103.841918000000
15 1.37739800000000 103.842093000000
16 1.37742900000000 103.842400000000
17 1.37744900000000 103.842629000000
18 1.37748100000000 103.842895000000
19 1.37750200000000 103.843164000000
20 1.37752800000000 103.843428000000
21 1.37756500000000 103.843689000000
22 1.37757000000000 103.843997000000
23 1.37758500000000 103.844248000000
24 1.37749200000000 103.844499000000
25 1.37765800000000 103.844515000000
26 1.37806100000000 103.844467000000
27 1.37853700000000 103.844386000000
28 1.37888000000000 103.844349000000
29 1.37924600000000 103.844303000000
30 1.37957500000000 103.844266000000
31 1.37966200000000 103.844190000000
32 1.37965300000000 103.844034000000
33 1.37963800000000 103.843813000000
34 1.37961600000000 103.843550000000
35 1.37959500000000 103.843313000000
36 1.37957600000000 103.843097000000
37 1.37957300000000 103.843007000000
38 1.37956800000000 103.842852000000
39 1.37953900000000 103.842602000000
40 1.37949900000000 103.842315000000
41 1.37948700000000 103.842056000000
42 1.37953800000000 103.841882000000
43 1.37967800000000 103.841755000000
44 1.37984000000000 103.841674000000
45 1.38007300000000 103.841546000000
46 1.38027900000000 103.841430000000
47 1.38044400000000 103.841354000000
48 1.38064800000000 103.841248000000
49 1.38092400000000 103.841100000000
50 1.38125600000000 103.840942000000
51 1.38178300000000 103.840682000000
52 1.38202300000000 103.840565000000
53 1.38236700000000 103.840396000000
54 1.38271600000000 103.840206000000
55 1.38302800000000 103.840017000000
56 1.38314600000000 103.840222000000
57 1.38299000000000 103.840230000000
58 1.38286700000000 103.840288000000
59 1.38265300000000 103.840398000000
60 1.38242100000000 103.840522000000
61 1.38219900000000 103.840638000000
62 1.38195100000000 103.840766000000
63 1.38162100000000 103.840934000000
64 1.38130200000000 103.841093000000
65 1.38106700000000 103.841202000000
66 1.38088500000000 103.841286000000
67 1.38069300000000 103.841372000000
68 1.38049000000000 103.841494000000
69 1.38018700000000 103.841659000000
70 1.37988900000000 103.841822000000
71 1.37966700000000 103.841963000000
72 1.37965000000000 103.842037000000
73 1.37965100000000 103.842220000000
74 1.37966300000000 103.842363000000
75 1.37968900000000 103.842641000000
76 1.37973000000000 103.843049000000
77 1.37975300000000 103.843305000000
78 1.37978200000000 103.843690000000
79 1.37982300000000 103.844135000000
80 1.37989800000000 103.844222000000
81 1.37996400000000 103.844230000000
82 1.38029900000000 103.844183000000
83 1.38080600000000 103.844091000000
84 1.38119600000000 103.843985000000
85 1.38170500000000 103.843838000000
86 1.38194900000000 103.843765000000
87 1.38220500000000 103.843683000000
88 1.38250000000000 103.843564000000
89 1.38296800000000 103.843388000000
90 1.38367400000000 103.843107000000
91 1.38379700000000 103.842994000000
92 1.38384900000000 103.842791000000
93 1.38376700000000 103.842173000000
94 1.38372500000000 103.841758000000
95 1.38358400000000 103.841212000000
96 1.38350400000000 103.840867000000
97 1.38324600000000 103.840388000000
98 1.38288200000000 103.839785000000
99 1.38265700000000 103.839436000000
100 1.38238700000000 103.838973000000
101 1.38224900000000 103.838785000000
102 1.38215800000000 103.838830000000
103 1.38197900000000 103.838933000000
104 1.38162900000000 103.839097000000
105 1.38115400000000 103.839338000000
106 1.38080900000000 103.839609000000
107 1.38036600000000 103.839756000000
108 1.37995000000000 103.839782000000
109 1.37957400000000 103.839826000000
110 1.37904400000000 103.839883000000
111 1.37844300000000 103.839807000000
112 1.37803700000000 103.839743000000
113 1.37765800000000 103.839690000000
114 1.37735600000000 103.839665000000
115 1.38310100000000 103.840134000000
116 1.38108800000000 103.841146000000
117 1.37961700000000 103.842951000000
118 1.37978200000000 103.844233000000
我的代码
M = xlsread('YCKMap.xlsx');
figure(),plot(M(:,2), M(:,3));
结果
http://i.stack.imgur.com/0dncY.jpg
我想要什么:
是否可以将这些点连接在一起 (55 115 56) (49 116 65) (37 117 76) (30 118 80) 如上图所示?
【问题讨论】:
你的问题有点含糊,可以用xlsread()在matlab中获取数据。发布您尝试过的内容。 我已经使用 .csv 将数据插入到 Matlab 中。数据采用矩阵格式。那么如何使用这些数据来构建轨迹线 请在您的问题中定义“跟踪线”的含义(编辑问题)。你只是想创造一个情节吗?如果您描述了您所追求的输出,将会有所帮助。 耶!!我认为是在谋划要点!但不只是将它们加入一条线,我希望它们按照地图中的路径加入 您需要对您的意思提供适当的解释,您的问题中没有足够的细节。将数据导入 matlab 后是什么样的,1 个矩阵,3 个向量?让我们假设它是 1 个称为 M 的矩阵,那么 plot(M(:,2), M(:,3)) 会做你想要的吗?如果不是,为什么不呢?如果不绘制数据点并按照它们出现的顺序连接它们,根据地图中的路径意味着什么? 【参考方案1】:我已经找到了我的问题的答案,并希望通过我提出的问题使社区受益。根据@Dan 代码plot(M(:,2), M(:,3);
可以绘制出点,但图形的方向偏离了。因此,我使用航点功能使其变得更好。
无论如何,当您想插入新行时,通过留出单元格间隙来组织您的 Excel 数据。 我已经粘贴了excel数据让你看的更清楚。
编码
M = xlsread('excel.xlsx');
waypoints =[M(:,2), M(:,3)];
[lttrk,lntrk] = track('rh',waypoints,'degrees');
figure(),geoshow(lttrk,lntrk,'DisplayType','line', 'color','r');
Excel 数据
1 1.377234 103.839645
2 1.37722 103.839741
3 1.377233 103.839843
4 1.377236 103.839968
5 1.377241 103.840125
6 1.377239 103.840245
7 1.377249 103.840435
8 1.377257 103.840674
9 1.377248 103.840896
10 1.377265 103.841071
11 1.377283 103.84119
12 1.377295 103.841393
13 1.377346 103.841591
14 1.377365 103.841918
15 1.377398 103.842093
16 1.377429 103.8424
17 1.377449 103.842629
18 1.377481 103.842895
19 1.377502 103.843164
20 1.377528 103.843428
21 1.377565 103.843689
22 1.37757 103.843997
23 1.377585 103.844248
24 1.377492 103.844499
25 1.377658 103.844515
26 1.378061 103.844467
27 1.378537 103.844386
28 1.37888 103.844349
29 1.379246 103.844303
30 1.379575 103.844266
31 1.379662 103.84419
32 1.379653 103.844034
33 1.379638 103.843813
34 1.379616 103.84355
35 1.379595 103.843313
36 1.379576 103.843097
37 1.379573 103.843007
38 1.379568 103.842852
39 1.379539 103.842602
40 1.379499 103.842315
41 1.379487 103.842056
42 1.379538 103.841882
43 1.379678 103.841755
44 1.37984 103.841674
45 1.380073 103.841546
46 1.380279 103.84143
47 1.380444 103.841354
48 1.380648 103.841248
49 1.380924 103.8411
50 1.381256 103.840942
51 1.381783 103.840682
52 1.382023 103.840565
53 1.382367 103.840396
54 1.382716 103.840206
55 1.383028 103.840017
56 1.383146 103.840222
57 1.38299 103.84023
58 1.382867 103.840288
59 1.382653 103.840398
60 1.382421 103.840522
61 1.382199 103.840638
62 1.381951 103.840766
63 1.381621 103.840934
64 1.381302 103.841093
65 1.381067 103.841202
66 1.380885 103.841286
67 1.380693 103.841372
68 1.38049 103.841494
69 1.380187 103.841659
70 1.379889 103.841822
71 1.379667 103.841963
72 1.37965 103.842037
73 1.379651 103.84222
74 1.379663 103.842363
75 1.379689 103.842641
76 1.37973 103.843049
77 1.379753 103.843305
78 1.379782 103.84369
79 1.379823 103.844135
80 1.379898 103.844222
81 1.379964 103.84423
82 1.380299 103.844183
83 1.380806 103.844091
84 1.381196 103.843985
85 1.381705 103.843838
86 1.381949 103.843765
87 1.382205 103.843683
88 1.3825 103.843564
89 1.382968 103.843388
90 1.383674 103.843107
91 1.383797 103.842994
92 1.383849 103.842791
93 1.383767 103.842173
94 1.383725 103.841758
95 1.383584 103.841212
96 1.383504 103.840867
97 1.383246 103.840388
98 1.382882 103.839785
99 1.382657 103.839436
100 1.382387 103.838973
101 1.382249 103.838785
102 1.382158 103.83883
103 1.381979 103.838933
104 1.381629 103.839097
105 1.381154 103.839338
106 1.380809 103.839609
107 1.380366 103.839756
108 1.37995 103.839782
109 1.379574 103.839826
110 1.379044 103.839883
111 1.378443 103.839807
112 1.378037 103.839743
113 1.377658 103.83969
114 1.377356 103.839665
1 1.377234 103.839645
49 1.380924 103.8411
116 1.381088 103.841146
65 1.381067 103.841202
37 1.379573 103.843007
117 1.379617 103.842951
76 1.37973 103.843049
30 1.379575 103.844266
118 1.379782 103.844233
80 1.379898 103.844222
【讨论】:
【参考方案2】:如果您想在 Matlab 中以与它们在矩阵中出现的顺序不同的顺序绘制点,请在矩阵的开头附加一个列向量,该列向量是点应该出现的顺序的向量。然后使用sortrowsmatlab 的函数重新排列矩阵。现在它将处于正确的绘图顺序。例如:
M = [0 4 2; 1 17 5]';
plot(M);
现在假设您知道正确的绘图顺序是 (0,1) 然后 (2,5) 然后 (4,17)。与输入矩阵M相比,正确的绘图顺序可以由order = [1 3 2]'
指定
所以要以正确的顺序绘制:
M = [order'; M'];
M = sortrows(M);
plot(M(:,2), M(:,3);
也就是说只要知道正确的绘图顺序,现在就可以使用这种方法得到正确的绘图了。
因此,在您的示例中,您希望按 (55 115 56) (49 116 65) (37 117 76) (30 118 80) 的顺序绘制这些点。假设您希望它们从 55 开始,因为这是您的新订单中的第一个点,目前 M 看起来像这样:M = [...;30 118 80;...;37 117 76;...;49 116 65;...;55 115 56;...] 但你希望它看起来像这样: M = [...; 55 115 56; 56 116 65; 57 117 76; 58 118 80;...]。问题是你不能只改变这样的值 M(M(:,1) == 30,1) = 58 因为那样你会得到 2 个索引为 58 的点。所以首先你需要添加 1也是所有 58 或更高的索引,所以 M(M(:,1) >= 58) = M(M(:,1) >= 58) + 1 然后最后是 M(M(:,1) = = 30,1) = 58. 所以概括一点的变化:
M(M(:,1) >= newIndex) = M(M(:,1) >= newIndex) + 1;
M(M(:,1) == oldIndex,1) = newIndex;
如果有一些逻辑可以定义你如何改变点,那么你可以把它写成一个循环。如果没有,只是这 4 点,那么只需在命令行中手动运行即可。
【讨论】:
我试图修改它,但它不起作用!!但无论如何,只是为了让你知道我已经更新了我的问题!希望这将更加具体,足以让您理解!无论如何感谢您的帮助! 上班怕是打不开第二个链接,不过听上去好像只是想换个点的顺序。您的第一列按从 1 到 118 的顺序排列。这就是您需要更改的内容。例如您提到的点:(55 115 56) (49 116 65) (37 117 76) (30 118 80),这些在您的矩阵中显示为 [...;30 118 80;...;37 117 76 ;...;49 116 65;...;55 115 56;...] 其中三个点代表它们之间的所有点。但是您希望这 4 个按顺序绘制。因此,您需要做的是更改每个值中的第一个值,以使值是连续的。查看答案编辑 感谢您的回复。但我也希望它从(1 到 114)加入。我怎么能编码!!我真的不知道如何开始 对不起,我真的不明白你想要什么。很高兴看到你自己解决了。以上是关于如何从excel中检索坐标并根据地图绘制点? - MATLAB的主要内容,如果未能解决你的问题,请参考以下文章