This function is based on UTM.m function by Gabriel Ruiz Martinez, but instead of providing a GUI it works with vectors of coordinates.
[x,y,utmzone] = deg2utm(Lat,Lon)
% Example 1:
% Lat=[40.3154333; 46.283900; 37.577833; 28.645650; 38.855550; 25.061783];
% Lon=[-3.4857166; 7.8012333; -119.95525; -17.759533; -94.7990166; 121.640266];
% [x,y,utmzone] = deg2utm(Lat,Lon);
% fprintf('%7.0f ',x)
% 458731 407653 239027 230253 343898 362850
% fprintf('%7.0f ',y)
% 4462881 5126290 4163083 3171843 4302285 2772478
% utmzone =
% 30 T
% 32 T
% 11 S
% 28 R
% 15 S
% 51 R
% Example 2: If you have Lat/Lon coordinates in Degrees, Minutes and Seconds
% LatDMS=[40 18 55.56; 46 17 2.04];
% LonDMS=[-3 29 8.58; 7 48 4.44];
% Lat=dms2deg(mat2dms(LatDMS)); %convert into degrees
% Lon=dms2deg(mat2dms(LonDMS)); %convert into degrees
% [x,y,utmzone] = deg2utm(Lat,Lon)
Hello, I wish to the equations in details, can someone provide comments or documents related to the equations.
How can we choose the utmzone, because when i run it the function the wrong utm zone which give me wrong results....
Solved your mismatch, Lea. The utm2deg function values should be filled with decimals, as shown below where I've replicated the author's example. Cheers
1.. Direct function:
>> format long g
>> Lat=[40.3154333; 46.283900; 37.577833; 28.645650; 38.855550; 25.061783];
>> Lon=[-3.4857166; 7.8012333; -119.95525; -17.759533; -94.7990166; 121.640266];
>> [x,y,utmzone] = deg2utm(Lat,Lon)
2.. Reverse function
format long g
x=[ 458730.69991953; 407652.894658174; 239026.690338915; 230253.368028571; 343898.229457034; 362850.016911846];
y=[4462881.35112379; 5126289.79627619; 4163082.87564856; 3171843.30844493; 4302284.74761666; 2772478.3578643];
utmzone=['30 T'; '32 T'; '11 S'; '28 R'; '15 S'; '51 R'];
Hi, Lea, in your test you mentioned the function utm2deg -> [Lat Lon] = utm2deg(x,y,zone)
which is unavailable here, where deg2utm is uploaded. Please, could you post it in order to allow someone (like me) to replicate your test?
I need to convert deg to utm and utm back to deg again. This is why I checked, what happens if I convert from one to the other over and over again:
[x y zone] = deg2utm(Lat,Lon);
disp([num2str(i) ' ' num2str(x) ' ' num2str(y)]);
[Lat Lon] = utm2deg(x,y,zone);
It appears, that already after ten times about 2mm are added in both directions:
1 452837.7301 6070927.9726
10 452837.7325 6070927.9747
This is not an issue to my work since the error is negligible in the scope of my work, but I am wondering if this is due to Matlab limitations in precision or due to the formulation of the transformation rule (or any other reason)?
how can i get it running because I wrote [x,y,utmzone] = deg2utm(355497.97,5787938.89) on the command window and its is giving me an error message
Excellent and easy to use!
Como descargo la función?
Same issue as tuan,
more than one utm zone gives
wrong X coordinates.
can someone help.
where is the function mat2dms and dms2deg?
It works fine for an area with single utmzone. But for area with location has more than one utmzone it produces X (East direction) not correctly.
Could anyone help me to figure out?
It was okay.. My mistake! Thanks
The function works perfectly, but I have doubts on the outputs: which one represents easting (i.e. longitudinal information) and which one the northing (latitudinal information)?
Oops, I got it to work - - just my newness to the software.
Forgot to specify the outputs I wanted.
For people like me (getting into matlab), make sure to put your outputs you want in the command window.
IE: [x,y,utmzone] = deg2utm(Lat,Lon), where if you want x, y, and the utmzone you have to tell matlab that. Else it will only give you x (which is what I was getting before hand).
EDU>> [x,y,utmzone] = deg2utm(38.130587, -99.081752)
x = 4.9284e+05
y = 4.2203e+06
utmzone = 14 S
i am unsure if this is a issue or not.
if i input the following:
i expect that the x output is the samme for both cordinates, and that i have a diferense of only 0.58m in the y, how ever the diference in x is about 1M and in y about 22,5M. any thoughts ?
thank you very much.
I have converted column 1 and 2, the deg2utm works perfectly fine. The lat/longs are from UTM zone 16 to zone 14 (from top to bottom). Note that easting suddenly increases as you move from a higher UTM zone number to lower one. There is not much change in Lats so that zone northing remains from letter Q. Column 3 and 4 has wrong transformed values.
I have problems converting the 1st and 2nd columns. The 3rd and 4th columns are the correct transformed values.. Any help?
18.9000000000000 -85.6000000000000 1016636.08476000 2097349.08510000
19.1000000000000 -86.2000000000000 952730.286652000 2117881.16418000
19.3000000000000 -86.7000000000000 899537.751857000 2138832.87892000
19.5000000000000 -87.2000000000000 846493.267934000 2159917.67197000
19.6000000000000 -87.5000000000000 814775.913438000 2170418.08636000
19.8000000000000 -87.9000000000000 772442.462010000 2191882.52618000
20.3000000000000 -88.8000000000000 677544.995001000 2246042.98172000
20.5000000000000 -89.8000000000000 573005.667765000 2267422.61128000
20.5000000000000 -91.0000000000000 447853.577293000 2267346.10988000
20.3000000000000 -91.7000000000000 374681.174733000 2245584.33154000
20.1000000000000 -92.2000000000000 322228.063533000 2223898.57802000
19.8000000000000 -93.2000000000000 217073.073883000 2192046.90591000
19.2000000000000 -94.1000000000000 121283.019710000 2127298.41915000
18.6000000000000 -94.9000000000000 35345.9851048000 2062679.39657000
17.9000000000000 -95.6000000000000 -40894.3144760000 1986930.91879000
17.2000000000000 -96.4000000000000 -128393.538814000 1911652.44510000
16.9000000000000 -97.0000000000000 -193630.694790000 1880339.46191000
arg, sorry my fault, its no bug
arg, sorry my fault, its no bug
I found a bug, in this example the first point P95 is mapped correctly to google maps, but EP2 differs about 70 Meters from GPS coordinates in carthesian:
P95 = [15.425789 47.030778];
[P95_Carthesian(1) P95_Carthesian(2)] = deg2utm(P95(2), P95(1));
EP2 = [15.42604688057756 47.03090763127457];
[EP2_Carthesian(1) EP2_Carthesian(2)] = deg2utm(EP2(2), EP2(1));
I have a question about this script:
I want to convert lat lon points in the Northern Shelf Sea (Europe) to coordinates which have the unit meters. So I thought using UTM coordinates was the best solution.
However, the area is quite big (1000km x 1000km) and contains different zones. So after converting, my points are not in the right order any more. So either it is simply not possible to have points of different zones in one data base or the script makes some mistake.
Can somebody help me with this issue?
Thank you. Anna
I have my Lat/Lon coordinates in Degrees, Minutes and Seconds (as in your Example 2). However I am missing the 'dms2deg' and 'mat2dms' functions. Are these in some toolbox or part of this submission.
Excellent Script! I wonder if you would provide some comments for the calculation section. I've compared some lat/lon data to actual x,y profiles; however, I've found that I must multiply the x and y valuse derived from deg2utm by approximately 3.2 to match the actual values?! Thanks! Again, great script!!!
Excellent!! And Thank you. This is applied for Korea.
Great stuff~ Thank you very much.
Very good ! Thank you very much !
Thanks a lot!
corrected m-Lint warnings
Fixed a problem with southern hemisphere coordinates. Now it works properly.
Update description. Minor fixes