Convert cell array to vector
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everybody,
I have a 1279x1 cell array containing timestamps and I want to convert it as a 1279x1 vector of interpretable time format.
My ultimate goal would be to get a vector with the time differences between 2 successive timestamps and get the mean of this vector.
Then I can calculate the sample rate.
I have absolutely no idea how to deal with cell arrays, so any help would be really nice !
You can see my cell array in the following and the complete cell array as a .mat file :
{["16:44:53.419"]}
{["16:44:53.435"]}
{["16:44:53.468"]}
{["16:44:53.483"]}
{["16:44:53.499"]}
{["16:44:53.515"]}
{["16:44:53.531"]}
{["16:44:53.563"]}
{["16:44:53.579"]}
{["16:44:53.595"]}
{["16:44:53.611"]}
{["16:44:53.627"]}
{["16:44:53.643"]}
{["16:44:53.675"]}
{["16:44:53.691"]}
{["16:44:53.707"]}
{["16:44:53.723"]}
{["16:44:53.739"]}
{["16:44:53.755"]}
{["16:44:53.770"]}
{["16:44:53.787"]}
{["16:44:53.803"]}
{["16:44:53.818"]}
{["16:44:53.835"]}
{["16:44:53.962"]}
{["16:44:53.978"]}
{["16:44:53.994"]}
{["16:44:54.010"]}
{["16:44:54.027"]}
{["16:44:54.042"]}
{["16:44:54.074"]}
{["16:44:54.090"]}
{["16:44:54.106"]}
{["16:44:54.122"]}
{["16:44:54.138"]}
{["16:44:54.154"]}
{["16:44:54.170"]}
{["16:44:54.186"]}
{["16:44:54.202"]}
{["16:44:54.218"]}
{["16:44:54.234"]}
{["16:44:54.266"]}
{["16:44:54.282"]}
{["16:44:54.298"]}
{["16:44:54.314"]}
{["16:44:54.330"]}
0 Commenti
Risposta accettata
Stephen23
il 20 Gen 2021
S = load('timestamps.mat');
T = vertcat(S.ans{:})
M = seconds(mean(diff(duration(T,'InputFormat','hh:mm:ss.SSS'))))
Più risposte (1)
Cris LaPierre
il 20 Gen 2021
T = load('timestamps.mat');
% Convert to a string array
ts = string(T.ans);
% Convert strings to durations
ts = duration(ts,'InputFormat',"hh:mm:ss.SSS","Format","hh:mm:ss.SSS");
% compute the difference between each row
dt = diff(ts);
% calculate the mean
mdt = mean(dt)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!