Convert part of a string to number

5 views (last 30 days)
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.

Accepted Answer

Paolo
Paolo on 17 Jun 2018
Edited: Paolo on 17 Jun 2018
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.

More Answers (0)

Categories

Find more on Data Type Conversion 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!