Convert cell array to vector
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2021-1-20
S = load('timestamps.mat');
T = vertcat(S.ans{:})
M = seconds(mean(diff(duration(T,'InputFormat','hh:mm:ss.SSS'))))
更多回答(1 个)
Cris LaPierre
2021-1-20
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!