Degrees-Minutes-Seconds Separation

2 ビュー (過去 30 日間)
Matthew Tyler Jeffries
Matthew Tyler Jeffries 2019 年 3 月 26 日
回答済み: Are Mjaavatten 2019 年 3 月 27 日
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]

採用された回答

Are Mjaavatten
Are Mjaavatten 2019 年 3 月 27 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by