How to extract cell array in matlab
显示 更早的评论
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.
采纳的回答
更多回答(3 个)
Sven
2011-11-21
1 个投票
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
Andrei Bobrov
2011-11-21
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 个评论
Sven
2011-11-21
Oh, 3 answers within minutes. Who will get the "accept" from Mr. Smart. The suspense is killing me!
;-)
Walter Roberson
2011-11-21
Mine will! None of the rest of you noticed that the ':' was a mandatory part of the output!
Andrei Bobrov
2011-11-22
@Sven: Walter :)
Mr Smart
2011-11-22
Walter Roberson
2011-11-21
> 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 个评论
Walter Roberson
2011-11-22
Based upon the previous answers, the following should also work:
datestr(datevec({'22.11.2011 13:58:56.16'}),':SS')
Mr Smart
2011-11-22
类别
在 帮助中心 和 File Exchange 中查找有关 Licensing on Cloud Platforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!