How can I convert this cell array into time stamps?

I have a cell array, 1729 x 1, and I need each cell converted. I've tried the datetime command but I only need HH:mm:ss.
>> t = datetime(.0028356,'ConvertFrom','datenum')
t =
datetime
31-Dec--0001 00:04:04

4 Comments

Where is the cell array?
it's an xls file. Here are 10 of the values.
'0.0039583'
'0.015058'
'0.0091898'
'0.012731'
'0.00061343'
'0.015799'
'0.0022917'
'0.036933'
'0.018819'
'0.0026042'
'0.0019213'
You said "cell array". Now you mention an xls file. Did you import the file already or is this a part of the problem?
I already imported the file.I am trying to convert one of the columns, 1729 x 1, into HH:mm:ss.

Sign in to comment.

 Accepted Answer

If I start by creating a cell array using the data you've shared:
tm = {'.0028356'
'0.0039583'
'0.015058'
'0.0091898'
'0.012731'
'0.00061343'
'0.015799'
'0.0022917'
'0.036933'
'0.018819'
'0.0026042'
'0.0019213'}
Then I can convert the entire column of datenums to HH:mm:ss using the code Jan shared after converting the char data to numbers.
t = datetime(str2double(tm),'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss')

2 Comments

This is a duplicate post (don't do that). Please see my response to your other post, because I don't think you are getting what you think you are getting.

Sign in to comment.

More Answers (1)

Jan
Jan on 3 Dec 2018
Edited: Jan on 3 Dec 2018
t = datetime(.0028356, 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss')

3 Comments

thank you! definitely going in the right direction.
Would i create a For loop to go through the entire array? OR is there a simpler approach?
Which array? You mentioned a cell array, but did not explain, where it occurs.
%import excel
encounters = readtable('Encounters.xlsx');
%assign columns to variables
encounters.Properties.VariableNames;
encoueterkey=encounters.EncounterKey;
starttime=encounters.StartTime;
endtime=encounters.EndTime;
confid=encounters.ConferenceId;
patient=encounters.Patient;
clinicnum=encounters.ClinicNumber;
patientintime=encounters.RequestorJoinTime;
patientouttime=encounters.RequestorLeftTime;
provider=unique(encounters.Provider);
providerintime=encounters.ProviderJoinTime;
providerouttime=encounters.ProviderLeftTime;
duration=encounters.Duration;
%convert serial time stamp (duration) to time format
t = datetime(duration, 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss');
this the error:
Error using datetime (line 614)
Unable to parse date/time text using the format 'HH:mm:ss'.
Error in EncounterAnalysis (line 21)
t = datetime(duration, 'ConvertFrom', 'datenum', 'Format', 'HH:mm:ss');

Sign in to comment.

Categories

Asked:

on 3 Dec 2018

Reopened:

on 29 Dec 2018

Community Treasure Hunt

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

Start Hunting!