My data is a 272×1 cell array see below
{'Geometry' }
{'X' }
{'Y' }
{'NR' }
{'X1' }
{'Y1' }
{'Easting' }
{'Northing' }
{'Height1' }
{'Def_Rate' }
{'Std_Dev' }
{'Height_unc'}
{'Def_Rate_u'}
{'D_20170729'}
{'D_20170810'}
{'D_20170816'}
{'D_20170822'}
I need the dates 20170729 ,20170810 .... can anyone help ASAP

 Respuesta aceptada

dpb
dpb el 1 de Feb. de 2021
Editada: dpb el 1 de Feb. de 2021

2 votos

>> datetime(extractAfter(c(contains(c,'D_')),'D_'),'InputFormat','yyyyMMdd')
ans =
4×1 datetime array
29-Jul-2017
10-Aug-2017
16-Aug-2017
22-Aug-2017
>>
Actually can simplify just a little to include the leading "D_" string as fixed string in the input format --
>> datetime(c(contains(c,'D_')),'InputFormat','''D_''yyyyMMdd')
ans =
4×1 datetime array
29-Jul-2017
10-Aug-2017
16-Aug-2017
22-Aug-2017
>>

Más respuestas (1)

Jan
Jan el 2 de Feb. de 2021

1 voto

With older Matlab versions:
match = strcnmp(data, 'D_', 2);
result = strrep(data(match), 'D_', '');

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Feb. de 2021

Comentada:

el 2 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by