Convert part of a string to number

조회 수: 9 (최근 30일)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2018년 6월 17일
댓글: Konstantinos Tsitsilonis 2018년 6월 17일
Hi all,
I have a set of coordinates imported from excel in string format. I would like to extract them as numbers in order to plot them. Any ideas?
An example of the coordinate cell array is below:
NA_PC = {'32º 32′ 10″ N.' '117º 06′ 11″ W.' ;
'32º 32′ 04″ N.' '117º 07′ 29″ W.' ;
'32º 31′ 39″ N.' '117º 14′ 20″ W.' ;
'32º 33′ 13″ N.' '117º 15′ 50″ W.' ;
'32º 34′ 21″ N.' '117º 22′ 01″ W.' ;
'32º 35′ 23″ N.' '117º 27′ 53″ W.' ;
'32º 37′ 38″ N.' '117º 49′ 34″ W.' ;
'31º 07′ 59″ N.' '118º 36′ 21″ W.' ;
'30º 33′ 25″ N.' '121º 47′ 29″ W.' ;
'31º 46′ 11″ N.' '123º 17′ 22″ W.' ;
'32º 21′ 58″ N.' '123º 50′ 44″ W.' ;
'32º 56′ 39″ N.' '124º 11′ 47″ W.' }
Thanks for your help in advance,
KMT.

채택된 답변

Paolo
Paolo 2018년 6월 17일
편집: Paolo 2018년 6월 17일
You can use regexp to simply match the digits in your input.
NA = regexp(NA_PC,'\d{2,3}','match')
The expression matches numbers with between 2 and 3 digits.
NA is a 12x2 cell array with the numerical values.
NA{1,1} =
'32' '32' '10'
NA{1,2} =
'117' '06' '11'
... and so on.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by