Convert part of a string to number

3 次查看(过去 30 天)
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