필터 지우기
필터 지우기

How to import timestamp from excel

조회 수: 3 (최근 30일)
jchris14
jchris14 2016년 8월 1일
이동: Dyuman Joshi 2023년 10월 12일
I have a large data set and the first and second column are date and time followed by other parameter readings. When i import this excel into MATLAB, the timestamp, for example: 0:00:02 gets imported as 2e-5. How do I format it to say 0:00:02 or something more proper so that i can plot the data?
Thanks for the help

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 1일
If your time vector is in the first column for example
[a,b,c]=xlsread('d1.xlsx')
out=datestr(a(:,1),'HH:MM:SS')
  댓글 수: 1
jchris14
jchris14 2016년 8월 1일
이동: Dyuman Joshi 2023년 10월 12일
Thank you for your help! it works!

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

추가 답변 (1개)

Bradley
Bradley 2023년 10월 12일
Just a bump, updated for Matlab 2022b:
To read data from an Excel file which includes time stamps, a couple of things: datestr is obsolete, and datatime is preferred. However, I had issues using datetime directly. Instead, I did it like this, for data contained in a range from A1 to Z100, with the time stamps contained in column A:
full_data = readtable(filename,'Sheet','Sheet Name','Range','A1:Z100','ReadVariableNames',0);
time_data = table2array(full_data(:,1));
% Note: table2array seems to automatically detect the source format by default, so the answer comes in as datetime
From there, you can do any normal thing... I found a couple of follow-up things like this:
dt = seconds(mean(diff(time_data)));
time_max = seconds(time_data(end) - time_data(1));
sim_time = 0:dt:time_max;
I'm sure the table2array call has some default 'opts' which make the formatting just happen to work out nicely for me. I didn't bother to dig deeper on that.
Thanks!

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by