MATLAB Answers

How to extract cell array in matlab

7 views (last 30 days)
Hello.. Anyone does know? I need to extract from cell array (1x1 cell). For example > '22.11.2011 13:58:56.16' from this (1x1 cell).I want to extract time in second (:56) .How can I do. Thanks.

  0 Comments

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 21 Nov 2011
c={'22.11.2011 13:58:56.16','22.11.2011 13:58:40.16'};
d=datevec(c);
floor(d(:,6))

  1 Comment

Sign in to comment.

More Answers (3)

Sven
Sven on 21 Nov 2011
If you have strings of dates, use datevec as follows:
[Y, M, D, H, MN, S] = datevec('22.11.2011 13:58:56.16');
You'll notice that S has the value "56.1600", so floor(S) gives you the seconds

  1 Comment

Sign in to comment.


Andrei Bobrov
Andrei Bobrov on 21 Nov 2011
out = datevec({'22.11.2011 13:58:56.16'},'dd.mm.yyyy HH:MM:SS')
out = out(end)
OR
out = sprintf(':%d',out(end))

  4 Comments

Show 1 older comment
Walter Roberson
Walter Roberson on 21 Nov 2011
Mine will! None of the rest of you noticed that the ':' was a mandatory part of the output!
Mr Smart
Mr Smart on 22 Nov 2011
Thanks to you also . :)

Sign in to comment.


Walter Roberson
Walter Roberson on 21 Nov 2011
> datestr(datenum({'22.11.2011 13:58:56.16'},'dd.mm.yyyy HH:MM:SS.FFF'),':SS')
ans =
:56
>> char(cellfun(@(T) T(end-5:end-3), {'22.11.2011 13:58:56.16'},'Uniform',0))
ans =
:56

  2 Comments

Walter Roberson
Walter Roberson on 22 Nov 2011
Based upon the previous answers, the following should also work:
datestr(datevec({'22.11.2011 13:58:56.16'}),':SS')

Sign in to comment.

Sign in to answer this question.