필터 지우기
필터 지우기

separating day month year from string

조회 수: 1 (최근 30일)
sermet
sermet 2015년 11월 7일
편집: dpb 2015년 11월 8일
%I have a text file with one row and several hundreds columns. The text file includes string values like;
01.01.2013
02.01.2013
03.01.2013
%I need to read the text file and separate the day, month and year as numeric values like;
day=[01;02;03]; month=[01;01;01]; year=[2013;2013;2013]

채택된 답변

dpb
dpb 2015년 11월 7일
편집: dpb 2015년 11월 8일
[d,mo,yr]=textread('yourfile','%2d.%2d.%4d');
if were only that column. For more columns, use the proper format string for the line including whichever columns care to skip entirely and read into a cell array via textscan then convert per above format string using the particular cell column holding the dates. Have to convert the cellstr array to character array so use
damoyr=celltomat(textscan(char(c(N),'%2d.%2d.%4d'));
where N is the column of the above cell array returned containing the date string.
Or, if you have recent release, there's a date formatting string '%d' that will parse dates/times directly.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by