Borrar filtros
Borrar filtros

Convert part of a string to number

3 visualizaciones (últimos 30 días)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis el 17 de Jun. de 2018
Comentada: Konstantinos Tsitsilonis el 17 de Jun. de 2018
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.

Respuesta aceptada

Paolo
Paolo el 17 de Jun. de 2018
Editada: Paolo el 17 de Jun. de 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.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by