How to read a complex alphanumeric string or cell

1 次查看(过去 30 天)
Hi, I've some troubles to generate a code to read a complex (for me) alphanumeric string (or cell).
I've a cell (4000x1) with a text file like this: 'Daily_cum_2013_05_30_09_59__2013_05_31_10_05.asc' I want to separate the two dates (2013-05-30 09:59 and 2013-05-31 10:05) and convert it to a date format.
I tryed with sscanf, strread, textscan comands, but I don't succeed. Like:
test = sscanf(text,'%*s %d'); %to not consider the first part of text
but it doesn't work.
Is it so difficult ?
Thanks in advance
Stefano

采纳的回答

Walter Roberson
Walter Roberson 2016-2-10
If you have a cell array C of strings to split this way, then
sC = regexp(C, '__', 'split');
will be a cell array the same size as C, in which each element is a 1 x 2 cell array of strings. If you then
sC = vertcat(sC{:});
then the result would be an N x 2 cell array in which the columns are the two sides of the '__'

更多回答(1 个)

Stefano Alberti
Stefano Alberti 2016-2-10
Thank you very much Walter!
Now I have a 4000x2 cell, wiht the precedent string splited.
Now I need to read this two string e convert to data.
What do You think that I may use ?
Thanks
Stefano
  3 个评论
Stefano Alberti
Stefano Alberti 2016-2-11
编辑:Stefano Alberti 2016-2-11
Error using datestr (line 177) Cannot convert input into specified date string. DATENUM failed.
this is the answer given by the software.
Thanks
How to delete 'Daily_cum_' before the split?
Stefano Alberti
Stefano Alberti 2016-2-11
编辑:Stefano Alberti 2016-2-11
Ok, I'm obtained the result with this code:
sC = regexp(F, 'Daily_cum_', 'split');
sC = vertcat(sC{:}); sC(:, 1) = [];
sC = regexp(sC, '\.asc', 'split');
sC = vertcat(sC{:});
sC = regexp(sC, '__', 'split');
now, I've a two columns with the splitted date.

请先登录,再进行评论。

类别

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