Degrees-Minutes-Seconds Separation

2 vues (au cours des 30 derniers jours)
Matthew Tyler Jeffries
Matthew Tyler Jeffries le 26 Mar 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]

Réponse acceptée

Are Mjaavatten
Are Mjaavatten le 27 Mar 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)

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB 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