필터 지우기
필터 지우기

from Excel Time Import and Use in Arithmetically in Matlab

조회 수: 2 (최근 30일)
snr matlb
snr matlb 2018년 2월 24일
댓글: snr matlb 2018년 3월 4일
Hi,
I have a problem about time values in Matlab. I prepared excel sheet which contains times. I set the cell format hh:mm:ss in Excel and write the times for example 10:10:00. In another cell, I write 00:08:00 after that I want to subtraction 00:08:00 from 10:10:00. Normally, I want to get 10:02:00. But, after make xlsread and datestr, it makes the matrix in char, but I dont want it. I want the matrix m*n like in Excel. but, after datestr all times is written in 1 column in char type in matlab. I want to make my calculations like this for example, after xlsread or another method, t1=a(1,1) then t2=a(2,3) and then x=t2-t1 and the result as 10:10:00 - 00:08:00 = 10:02:00. Is it possible?
Thank you.

채택된 답변

Guillaume
Guillaume 2018년 2월 24일
Save yourself a lot of trouble if you are using an mildly recent version of matlab (R2014b or later) and use readtable instead of xlsread which will import your excel file more easily, and convert your time into modern datetime instead of the outdated datestr.
datetime knows how to calculate time differences properly.
data = readtable('yourexcelfile'); %usually it's all that is needed
timediff = diff(data.yourtimecolumn); %for example
  댓글 수: 5
Peter Perkins
Peter Perkins 2018년 2월 26일
The times are being read in as Excel date numbers. 0.41667 is (a rounded version of) 10/24.
Convert to durations:
>> x = 10/24
x =
0.416666666666667
>> t = days(x); t.Format = 'hh:mm:ss'
t =
duration
10:00:00
Because of the inherit round-off in Excel's representation of time, you are likely to get some round-off creeping in. You might consider rounding those durations to the nearest second or whatever.
It's also possible that your file also has dates, in which case you probably want to combine date+time and use datetimes, not durations.
snr matlb
snr matlb 2018년 3월 4일
thanks. now going on with numbers instead of time.

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

추가 답변 (0개)

카테고리

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