finding distance from text data for latitude/longitude and creating new column of data for distance
Mostrar comentarios más antiguos
Hello all,
I have a series of text files with latitude/longitude data, in seperate columns, and time in another column. I would liek to use the latitude/longitude data to make a distance vs. time plot.
formula for distance based on lat/long:
R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
The syntax isnt correct above as its not matlab code, just a formula on the internet.
How would I go about defining a new column of data (distance) by having it find the difference between every point of lat and long and then run the other basic operations to find distance?
the data in the text would follow this format;
Latitude Longitude
51.8885857 -2.159813307
51.888588 -2.159810551
51.88858751 -2.159811237
51.88858772 -2.159810981
51.88858774 -2.159810887
51.88858765 -2.159811144
51.88858779 -2.159810991
51.88858747 -2.159811489
51.88858758 -2.159811597
51.88858755 -2.15981158
51.88858725 -2.159811985
51.88858732 -2.159812218
1 comentario
douglas
el 13 de Abr. de 2012
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 13 de Abr. de 2012
use function distance from Mapping Toolbox
LatLon = [51.8885857 -2.159813307
51.888588 -2.159810551
51.88858751 -2.159811237
51.88858772 -2.159810981
51.88858774 -2.159810887
51.88858765 -2.159811144
51.88858779 -2.159810991
51.88858747 -2.159811489
51.88858758 -2.159811597
51.88858755 -2.15981158
51.88858725 -2.159811985
51.88858732 -2.159812218]
s1 = size(LatLon,1)
k = nchoosek(1:s1,2)
d = deg2km(distance(LatLon(k(:,1),1),LatLon(k(:,1),2),...
LatLon(k(:,2),1),LatLon(k(:,2),2))) ;
dout = zeros(s1);
dout(tril(true(s1),-1)) = d;
dout = dout + dout';
variant without Mapping Toolbox
L = [51.8885857 -2.159813307
51.888588 -2.159810551
51.88858751 -2.159811237
51.88858772 -2.159810981
51.88858774 -2.159810887
51.88858765 -2.159811144
51.88858779 -2.159810991
51.88858747 -2.159811489
51.88858758 -2.159811597
51.88858755 -2.15981158
51.88858725 -2.159811985
51.88858732 -2.159812218];
R = 6371;
dla = abs(bsxfun(@minus,L(:,1),L(:,1)'));
dlo = abs(bsxfun(@minus,L(:,2),L(:,2)'));
lac = cosd(L);
a = sind(dla/2).^2 + lac(:,1)*lac(:,1)'.*sind(dlo/2).^2;
d = R*2*atan2(sqrt(a), sqrt(1 - a)) ;
on Douglas's comment
out1 = diag(d,1)
out2 = cumsum(out1)
Categorías
Más información sobre Data Import and Export en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!