extracting dates within a text

조회 수: 11 (최근 30일)
Sadegh Nabavi
Sadegh Nabavi 2019년 11월 30일
댓글: Sadegh Nabavi 2019년 11월 30일
Good day all,
I have a csv file with texts and and dates mixed in each cell. I need to extract the dates that follow a specific text and store them in cell arrays. Example: "MovExperiment/MovingBarParameters started at 2018-04-17_09-32-11"; please see highlighted cells in the attached image.
What is the efficient way to do this?
Thanks,
Sadegh
  댓글 수: 1
dpb
dpb 2019년 11월 30일
Dunno and can't experiment without a copy of the significant portion of the file to look at.
Attach a (smallish) section of the file, not an image.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2019년 11월 30일
편집: dpb 2019년 11월 30일
matchstr='LoomingExp'; % string to match
c=textread('book1.csv','%s','delimiter',''); % read as cellstr array
c=char(c(contains(c,matchstr))); % save those with matching string/convert to char array
dt=datetime(c(:,end-18:end),'InputFormat','yyyy-MM-dd_HH-mm-ss'); % convert date strings to datetime
textread has been deprecated by TMW, but it's still useful in being able to do many things without the bother of having to have a file handle but using the filename directly.
  댓글 수: 3
dpb
dpb 2019년 11월 30일
Oh. I had done char() to convert to character array at command line but missed it when cut and pasted...
c=char(c(contains(c,'LoomingExp')));
Updated Answer
Sadegh Nabavi
Sadegh Nabavi 2019년 11월 30일
Thanks a lot. It works smoothly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by