Convert time data from excel format to milliseconds.
Show older comments
HI
I have a problem where i am trying to import time data from the excel format (0.914513888888889), into the Hour, Minute, Second< Millisecond format ('21:56:54:000').
The only problem is that the data i have from excel does not actually hold the information about the milliseconds. I have tried multiple ways of trying to perform a calculation on the data to extract some kind of millisecond data but can not figure it out.
I would also prefer if the time data was not stored as a string.
I will wattch my code. some parts are commented out as these parts i was attempting to use to get the millisecond data.
Any help would be hugley appreciated.
clc;
clear;
close all;
All_Data = {}; % set up cell array for all workbook data
for i = 1:11 % set up loop to run for 11 iterations (no. of workbooks)
filename = sprintf('%03d.xlsx', i); % set up each filename 001-011 to be read on each iteration
opt = detectImportOptions(filename); % import data from filename
sheets = sheetnames(filename); % retrieve names of sheets
for j = 1:numel(sheets) % iterate over each sheet within a workbook
tBC = readtable(filename, opt, 'Sheet', sheets{j}); % extract sheets from workbooks
Time_Data = tBC{:, 'Var4'}; % extract time data from column 4
ECG_Data = tBC{:, 'Var6'}; % extract ECG data from column 6
PPG_Data = tBC{:, 'Var8'}; % extract PPG data from column 8
SYS_Data = tBC{:, 'Var10'}; % extract reference systolic pressure data from column 10
DIA_Data = tBC{:, 'Var12'}; % extract reference diastolic pressure data from column 12
% Convert time data to the desired format
Time_Formatted = datestr(Time_Data, 'HH:MM:SS:fff'); % Format time data with milliseconds
% Time_Formatted = cellstr(Time_Formatted);
% Time_Formatted = split(Time_Formatted,':');
% Time_Formatted = str2cell(Time_Formatted);
%MS = ((((Time_Formatted/60)/60)/1000));
% Convert numerical data to cell arrays
Time_Data_Cell = num2cell(Time_Data);
ECG_Data_Cell = num2cell(ECG_Data);
PPG_Data_Cell = num2cell(PPG_Data);
SYS_Data_Cell = num2cell(SYS_Data);
DIA_Data_Cell = num2cell(DIA_Data);
% Place the formatted time data and numerical data in the first row
All_Data{i, j} = [cellstr(Time_Formatted), ECG_Data_Cell, PPG_Data_Cell, SYS_Data_Cell, DIA_Data_Cell];
% All_Data{i, j} = [Time_Data_Cell, ECG_Data_Cell, PPG_Data_Cell, SYS_Data_Cell, DIA_Data_Cell];
end
end
7 Comments
n = 0.914513888888889;
d = days(n);
d.Format = 'hh:mm:ss.SSS'
"The only problem is that the data i have from excel does not actually hold the information about the milliseconds."
So in lieu of actual data you just want to invent some millisecond values?
NeedHelp55
on 1 Mar 2024
You can use COLON and LINSPACE with both DURATION and DATETIME values:
linspace(seconds(0),seconds(1),7)
linspace(datetime,datetime+minutes(1),4)
Do you know the start&end times (and presumably how many times) or e.g. the start and step size?
NeedHelp55
on 1 Mar 2024
NeedHelp55
on 1 Mar 2024
Stephen23
on 1 Mar 2024
Were the data originally sampled at a regular interval?
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




