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.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 11월 21일

1 개 추천

c={'22.11.2011 13:58:56.16','22.11.2011 13:58:40.16'};
d=datevec(c);
floor(d(:,6))

추가 답변 (3개)

Sven
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
Andrei Bobrov 2011년 11월 21일

1 개 추천

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
Sven 2011년 11월 21일
Oh, 3 answers within minutes. Who will get the "accept" from Mr. Smart. The suspense is killing me!
;-)
Walter Roberson
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
Andrei Bobrov 2011년 11월 22일
@Sven: Walter :)
Mr Smart
Mr Smart 2011년 11월 22일
Thanks to you also . :)

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 11월 21일

1 개 추천

> 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
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
Mr Smart 2011년 11월 22일
Thanks you, Walter

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터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!

Translated by