Degrees-Minutes-Seconds Separation

3 views (last 30 days)
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]

Accepted Answer

Are Mjaavatten
Are Mjaavatten on 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)

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!