Calculating Distances with MATLAB's For Statement

  • Context: MATLAB 
  • Thread starter Thread starter hgphtgi
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The forum discussion centers on a MATLAB code snippet designed to calculate distances between a series of points defined by latitude and longitude. The starting coordinates are set at 3.682043 (latitude) and 101.523710 (longitude), with the destination coordinates at 2.227804 (latitude) and 103.35091 (longitude). The code utilizes nested for loops to iterate through potential points, but the validity of the custom 'distance' function remains in question, as it is not a standard MATLAB function.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with geographic coordinate systems (latitude and longitude)
  • Knowledge of custom function creation in MATLAB
  • Basic concepts of distance calculation between two points on a map
NEXT STEPS
  • Research how to implement custom functions in MATLAB
  • Learn about MATLAB's built-in functions for geographic distance calculations
  • Explore the use of vectorization in MATLAB to optimize distance calculations
  • Study the Haversine formula for calculating distances between two geographic points
USEFUL FOR

This discussion is beneficial for MATLAB programmers, geospatial analysts, and anyone involved in geographic data analysis or distance computation in MATLAB.

hgphtgi
Messages
12
Reaction score
0
Hello Guys

Can you please tell me whether this code is correct or not??

this code use to calculate all distances from A to J points on the map ( has longitude and latitude ), the starting point coordinates ( Lat and Long ) is 3.682043 and 101.523710 and the destination is 2.227804 103.35091

for p1=3.682043:-0.5:2.227804
for p2=101.523710:0.5:103.735091


a5= 2.227804;
b5=103.35091;

[dDgree] = distance(p1,p2,a5,b5); %% this function used to find a distance between two coordinates

end
end
 

Attachments

  • 2untitled.JPG
    2untitled.JPG
    21.6 KB · Views: 462
Physics news on Phys.org
I've never seen a "distance" function- did you write it yourself?
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
13
Views
4K
  • · Replies 18 ·
Replies
18
Views
4K