필터 지우기
필터 지우기

Importing data with date and time columns

조회 수: 2 (최근 30일)
David du Preez
David du Preez 2016년 6월 29일
댓글: Star Strider 2016년 6월 29일
I have a large data set in excel. In column A are dates(2015-01-01) and in column B are times(0:00).How do I import this into Matlab?

채택된 답변

Star Strider
Star Strider 2016년 6월 29일
Import it using the xlsread function.
I assume you already knew that, and want to know how to combine the date and time strings to create a valid date number. You can take advantage of the fact that MATLAB uses square brackets [] to concatenate strings.
Something like this will work:
dt = '2015-01-01';
tm = '12:34';
dn = datenum([dt tm], 'yyyy-mm-ddHH:MM')
ds = datestr(dn) % Check Conversion (Optional)
ds =
01-Jan-2015 12:34:00
  댓글 수: 2
David du Preez
David du Preez 2016년 6월 29일
I have tried that and it still doesn't work. When I use the xlsread function to import the data. Matlab ignores column A. Attached is a sample of the data and it continues like that for the rest of the year.
Star Strider
Star Strider 2016년 6월 29일
This works:
[d,s] = xlsread('David du Preez Book1.xlsx');
dn = datenum(s(2:end,1), 'mm/dd/yyyy') + d(:,1);
ds = datestr(dn) % Check Conversion (Optional)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by