Split number into parts

조회 수: 7 (최근 30일)
Richard Youden
Richard Youden 2018년 3월 15일
편집: Stephen23 2018년 3월 15일
I have a logger which records lat and long GPS data in Degrees Minutes Decimal format and I need to convert it into Degrees Decimal. For example the format from the logger is:
3947.787, -10454.28
I need to split this into:
39 47.787 -104 54.28
I can then convert these values into Degrees Decimal. The part I'm struggling with in my head is having the degrees value either 2 or 3 characters. If they where all the same size I think it's be far easier.
Thanks in advance everyone.
  댓글 수: 1
James Tursa
James Tursa 2018년 3월 15일
Do you have those lat/long values in your MATLAB workspace as char data or as double data?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 3월 15일
편집: Stephen23 2018년 3월 15일
If the minutes always has exactly two digits then this can be easily solved using a regular expression:
>> str = '3947.787, -10454.28';
>> tkn = regexp(str,'(\d+)(\d{2}\.\d+)','tokens');
>> str2double(vertcat(tkn{:}))
ans =
39 47.787
104 54.28
Note that this regular expression will not work if minutes can have other than two digits.
  댓글 수: 1
Richard Youden
Richard Youden 2018년 3월 15일
Thanks, that works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by