Degrees-Minutes-Seconds Separation

2 visualizaciones (últimos 30 días)
Matthew Tyler Jeffries
Matthew Tyler Jeffries el 26 de Mzo. de 2019
Respondida: Are Mjaavatten el 27 de Mzo. de 2019
I would like to take a column of data (as a string array) that contains degrees-minutes-seconds, and separate each of the values.
I'm starting with this:
23°10'5''
24°20'10''
25°30'15''
26°40'20''
And I would like to have this:
[23 10 5; 24 20 10; 25 30 15; 26 40 20]

Respuesta aceptada

Are Mjaavatten
Are Mjaavatten el 27 de Mzo. de 2019
It simplifies things if you use a doubke quote (") instead of two single qotes ('') to denote seconds. I enclose the modified input as the attached file "jeffries.txt". The foillowing code will then do the job:
fid = fopen('jeffries.txt');
c = textscan(fid,'%s','delimiter','\n');
fclose(fid);
c = c{1};
A = zeros(4,3);
for i = 1:length(c)
s = c{i};
deg = strfind(s,'°');
min = strfind(s,'''');
sec = strfind(s,'"');
A(i,1) = str2num(s(1:deg-1));
A(i,2) = str2num(s(deg+1:min-1));
A(i,3) = str2num(s(min+1:sec-1));
end
disp(A)

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by