Remove adjacent identical elements in coordinate vector

2 次查看(过去 30 天)
Hello, I have a code with longitude/latitude vectors of five values each. The code then splits them up into more intervals as seen. The code uses cell2mat in order to make a vector again. The problem is when I try to eliminate the adjacent identical elements in the vectors. As there are five coordinate pairs, there are going to be three instances where the values are identical adjacent. The code only removes one of these. Does anyone know why this is?
%Code:
clearvars latitude1
clearvars longitude1
% Coordinates:
Lat = [52.4686277562760;50.1205221900001;47.3391453706978;40.3182078293400;40.4990093049822];
Lon = [4.53197642865678;-0.521349043140527;-12.9336235413268;-72.7358453601434;-73.9159333378978];
% Divide vector into more intervals:
for i = 1:length(Lat)-1
[latitude1{i},longitude1{i}] = gcwaypts(Lat(i),Lon(i),Lat(i+1),Lon(i+1),25);
end
latitude1 = cell2mat(latitude1');
latitude = latitude1([1,diff(latitude1')]~=0);
longitude1 = cell2mat(longitude1');
longitude = longitude1([1,diff(longitude1')]~=0);
When I copy the latitude1 and longitude1 vectors as values into another script and run the rest, it works. But as this is a generic code, I would like the code to run without defining the latitude1 and longitude2 vectors manually. I do not wish to use the unique code, as values are allowed to be equal, just not when adjacent.
Put simply; the code for removing identical adjacent values in the vectors does not work. Please help me fix this.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Guidance, Navigation, and Control (GNC) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by