Effacer les filtres
Effacer les filtres

how to write values with dms2degrees

7 vues (au cours des 30 derniers jours)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA le 31 Oct 2022
what i have to do is insert an excel table where the coordinates are in degrees, minutes and seconds and convert it to decimal degrees.
the table that is I structured in this way:
ellipses_points_x1 ellipses_points_y1 thickness_cm eruptive_center_x0 eruptive_center_y0 eccentricity volume_published_km3
176° 00' 45,8593 38° 51' 42,6182 200 175°59'0.1,9978 38°79'94,3831 0,74 6
176° 02' 57,5069 38° 52' 19,6326 200
176° 06' 04,0076 38° 46' 34,9070 200
176° 02' 57,5069 38° 47' 09,1154 200
175° 56' 11,5936 38° 35' 12,6413 3
175° 59' 43,6924 38° 32' 26,7981 3
data2 = T_elchichon(:,{'ellipses_points_x1'});
angleInDegrees = dms2degrees(data2);
I have to convert all these coordinates to be able to use them to calculate distances. I found the dms2degrees function but in any case if I select for example a column it does not give me the result. the mistake it gives me is
Error using dms2degrees>validateInput (line 63)
DMS input array must be real-valued.
Error in dms2degrees (line 52)
validateInput(dms)
does the excel table have to be prepared in any particular way?Can anyone help me?
thanks
  4 commentaires
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA le 1 Nov 2022
but as it is visible in the excel that I have attached, I have many coordinates in the column.
I can't rewrite them one coordinate at a time.
is there any way to convert the whole column to decimal degrees at the same time?
or convert a table with 3 columns into a matrix and then use this method you suggested?
Torsten
Torsten le 1 Nov 2022
I have no experience with reading of string matrices and later conversion to numerical values.
Maybe someone else in the forum can help here.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 1 Nov 2022
This is a real challenge.
There must be an easier way to do this, however if there is, it eludes me.
I wrote my own function to do the conversion —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1175293/hatepe.xlsx')
T1 = 44×7 table
ellipses_points_x1 ellipses_points_y1 thickness_cm eruptive_center_x0 eruptive_center_y0 eccentricity volume_published_km3 ____________________ ___________________ ____________ ___________________ __________________ ____________ ____________________ {'176° 00' 45,8593'} {'38° 51' 42,6182'} 200 {'175°59'0.1,9978'} {'38°79'94,3831'} 0.74 6 {'176° 02' 57,5069'} {'38° 52' 19,6326'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 06' 07,6644'} {'38° 51' 56,8552'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 09' 03,1945'} {'38° 50' 45,6625'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 09' 54,3908'} {'38° 48' 51,7131'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 08' 55,8808'} {'38° 46' 57,7131'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 06' 04,0076'} {'38° 46' 34,9070'} 200 {0×0 char } {0×0 char } NaN NaN {'176° 02' 57,5069'} {'38° 47' 09,1154'} 200 {0×0 char } {0×0 char } NaN NaN {'175° 56' 11,5936'} {'38° 35' 12,6413'} 3 {0×0 char } {0×0 char } NaN NaN {'175° 59' 43,6924'} {'38° 32' 26,7981'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 03' 45,0463'} {'38° 29' 46,5729'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 07' 31,7726'} {'38° 27' 46,3390'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 13' 30,1465'} {'38° 25' 00,2101'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 20' 27,0304'} {'38° 22' 31,1767'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 27' 23,9143'} {'38° 21' 05,1570'} 3 {0×0 char } {0×0 char } NaN NaN {'176° 36' 32,4457'} {'38° 19' 56,3209'} 3 {0×0 char } {0×0 char } NaN NaN
T1{:,1} = num2cell(convertColumn(T1{:,1}));
T1{:,2} = num2cell(convertColumn(T1{:,2}))
T1 = 44×7 table
ellipses_points_x1 ellipses_points_y1 thickness_cm eruptive_center_x0 eruptive_center_y0 eccentricity volume_published_km3 __________________ __________________ ____________ ___________________ __________________ ____________ ____________________ {[176.0127]} {[38.8618]} 200 {'175°59'0.1,9978'} {'38°79'94,3831'} 0.74 6 {[176.0493]} {[38.8721]} 200 {0×0 char } {0×0 char } NaN NaN {[176.1021]} {[38.8658]} 200 {0×0 char } {0×0 char } NaN NaN {[176.1509]} {[38.8460]} 200 {0×0 char } {0×0 char } NaN NaN {[176.1651]} {[38.8144]} 200 {0×0 char } {0×0 char } NaN NaN {[176.1489]} {[38.7827]} 200 {0×0 char } {0×0 char } NaN NaN {[176.1011]} {[38.7764]} 200 {0×0 char } {0×0 char } NaN NaN {[176.0493]} {[38.7859]} 200 {0×0 char } {0×0 char } NaN NaN {[175.9366]} {[38.5868]} 3 {0×0 char } {0×0 char } NaN NaN {[175.9955]} {[38.5408]} 3 {0×0 char } {0×0 char } NaN NaN {[176.0625]} {[38.4963]} 3 {0×0 char } {0×0 char } NaN NaN {[176.1255]} {[38.4629]} 3 {0×0 char } {0×0 char } NaN NaN {[176.2250]} {[38.4167]} 3 {0×0 char } {0×0 char } NaN NaN {[176.3408]} {[38.3753]} 3 {0×0 char } {0×0 char } NaN NaN {[176.4566]} {[38.3514]} 3 {0×0 char } {0×0 char } NaN NaN {[176.6090]} {[38.3323]} 3 {0×0 char } {0×0 char } NaN NaN
function deg = convertColumn(x)
c = strrep(x,',','.');
v1 = regexp(c, '(\d*)','match');
v1m = reshape(str2double([v1{:}]), 4, []).';
v2 = regexp(c,'(\d*\.\d*)', 'match');
v2m = str2double([v2{:}]);
deg = dms2degrees([v1m(:,1:2) v2m.']);
end
This would be straightforward with str2angle, however the quadrant characters ('N', 'E', etc.) are missing and the function requires them.
.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by