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!