The disthist function creates a histogram of distances between geolocated waypoints assuming a great circle path along the WGS84 ellipsoid.
disthist(lat,lon) disthist(lat,lon,distances_or_nbins) n = disthist(...) [n,xout] = hist(...)
disthist(lat,lon) without output arguments produces a histogram plot of the output of distances between points given by geographic coordinates lat and lon. disthist distributes the bins along the x-axis between the minimum and maximum values of distances between points in meters.
disthist(lat,lon,distances_or_nbins) specifies an array of distances between points (equivalent to x in the hist function) or the scalar number of bins. By default distances_or_nbins = 10.
n = disthist(...) does not produces a histogram plot, but only returns the number of elements in each bin as described above.
[n,xout] = hist(...) returns vectors n and xout containing the frequency counts and the bin locations. You can use bar(xout,n) to plot the histogram.
This example uses the built-in sample_route.gpx route.
route = gpxread('sample_route.gpx'); % some sample data lat = route.Latitude; lon = route.Longitude; % Create a map of the route: figure subplot(2,1,1) usamap([min(lat) max(lat)],[min(lon) max(lon)]) plotm(lat,lon,'ko-') % See the distribution of distances between measured GPS points: subplot(2,1,2) disthist(lat,lon,45) box off; axis tight; xlabel('distances between waypoints (meters)')
Meridians converge at the poles, so a grid that is regular in lat/lon space will not be regular in xy space. Similarly, a path interpolated to equal spacing in lat/lon space will consist of points that are not equally spaced in terms of distance.
copenhagen = [55.7 12.6]; % Geographic coordinates of Copenhagen shanghai = [31.2 121.5]; % Geographic coordinates of Shanghai % Interpolate a path from Rio to Shanghai at ~1/1000 degree spacing: [lats,lons] = interpm([copenhagen(1) shanghai(1)],[copenhagen(2) shanghai(2)],.001); figure disthist(lats,lons) box off; axis tight xlabel('distances between waypoints (meters)')
Chad Greene created this on June 17 2014. Requires the Mapping Toolbox.
See also hist and distance.