## Distance measurement between two locations on Earth in MatLab

Suppose, you need to calculate distance between two locations on Earth in kilometers. And suppose you know their geographical coordinates, i.e. [latitude, longitude]. In MatLab there is a function *distance(lat1, lon1, lat2, lon2)*. It calculates distance between two points in angle units (in degrees there). So, you can calculate distance between two objects in angle units. Next you should to convert angle units into kilometers. Use for this *distdim(angle,’deg’,’kilometers’) *function.

For example you need to find distance between Minsk, Belarus (53.9, 27,5667 [53° 54′ 0″ N, 27° 34′ 0″ E]) and Caracas, Venezuela (10.5207, -66.9245 in [10° 31′ 14.52″ N, 66° 55′ 28.2″ W]).

Type:

>> distdim(distance(53.9, 27.5667, 10.5207, -66.9245),'deg','kilometers')

Result will be 9355.484 kilometers.

Tags: distance measurement, MatLab

May 4th, 2015 at 4:30 pm

Hi,

When I try the syntax in Matlab, the following message appears:

>> distance(53.9, 27.5667, 10.5207, -66.9245)

Undefined function ‘distance’ for input arguments of type

‘double’.

Where can I find the function distance.m that you seem to have?

Thanks a lot!