Yoolla
Yoolla

Reputation: 43

How to do calculation on time values imported from Excel?

I have the following values in Excel:

I want to import them into MATLAB and do some calculation on these time values such as subtraction. The time values look like this after importing:

and obviously doing calculation on them would be nonsense. Would any body help me with this issue? I have stuck with it for few days, and no progress yet.

Thanks in advance,

Upvotes: 4

Views: 63

Answers (1)

Dominic
Dominic

Reputation: 403

As assylias pointed out, these are fractions of days. You can use the datestr function to convert it to human-readable strings with formatting option conveniently.

e.g.:

datestr(0.2917, 'HH:MM:SS')

ans =    
07:00:02

Calculations such as subtractions can be done on the raw values before conversion.

E.g: get duration of sleep.

start = 0.8208
stop = 0.2917

datestr(stop-start, 'HH:MM')

ans =
11:18

Even works for intervals that span over midnight.

Upvotes: 1

Related Questions