필터 지우기
필터 지우기

How to import excel sheet with Dates/Time in the first column

조회 수: 8 (최근 30일)
Giancarlo Meccariello
Giancarlo Meccariello 2020년 10월 10일
댓글: Walter Roberson 2020년 10월 12일
Hello,
In the first column I have the dates written as 01.12.2019 00:00 in the other column I have datas as floating numbers.
If I import the excel sheet with "Data=xlsread('Filename') " I don't get the dates and times in the first column instead some random floating numbers.
I need the dates to make a graph with them on the X axis.
please help
  댓글 수: 2
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 10일
can you add example data cloumn here.
Giancarlo Meccariello
Giancarlo Meccariello 2020년 10월 10일
A B C
1 01.12.2019 00:00 48 20
2 01.12.2019 00:15 47 21
3 01.12.2019 00:30 49 20.5

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

답변 (2개)

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 10일
  1. try
[num,txt,raw] = xlsread(filename)
2. check also readtable, readmatrix, or readcell
  댓글 수: 2
Giancarlo Meccariello
Giancarlo Meccariello 2020년 10월 10일
doesn't work.
I get 3 files
first just with numbers -> same as I had
second just text -> date and time is not written as text
and third is kinda mix between 1st and 2nd.
this is the format in excel of my date and time "TT.MM.JJ hh:mm"
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 12일
[~,~,raw] = xlsread(filename);
%Extract date column if date is 2 nd column in excel
Date = raw(:,2);
%ignore Date header
Date = raw(2:end,2);

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


Giancarlo Meccariello
Giancarlo Meccariello 2020년 10월 12일
I found a solution.
basically when the format for the date in excel is TT.MM.JJ hh:mm and you import the excel as a matrix you get the serial number of the date. that's something linke 44380.
then you have to add a constant, that's the deviation between matlab and excel in the serial number of the dates
date_matrix=DATA(:,1) + 693960
and finally it has to be converted to date
date_for_plots = datetime(date_matrix,'ConvertFrom','datenum')
Now graphs can be plotted with this vector for the X-axis
  댓글 수: 2
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 12일
Yup. You can also look for datestr
Walter Roberson
Walter Roberson 2020년 10월 12일
date_for_plots = datetime(DATA(:,1), 'convertfrom', 'excel');

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

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by