Can you please tell me whether this Matlab code whether 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
The code that you posted and the requirements of calculating distances is not clear enough. We don't know if you are calculating distances for every point at 0.5 increments/decrements or if you already have a set of pre-defined points to calculate the distance to the destination. (i.e. you have a range of 3.682043 to 2.227804, however, your program will stop at 2.68204)
Right now, the best tool to make sure you code is running correctly is to use indicators for your variables to double-check the execution of your script. You can insert these variables at specific points in your program to help troubleshoot program flow: