How to modify data vector

조회 수: 4 (최근 30일)
Valerio Gianforte
Valerio Gianforte 2020년 2월 25일
댓글: Giuseppe Inghilterra 2020년 2월 25일
time1=
125×1 int32 column vector
19850101
19850101
19850101
19850101
19850102
19850102
19850102
19850102
19850103
19850103
19850103
19850103
19850104
19850104
19850104
19850104
Hi everyone,
I have a vector (time1) that conain 'year', 'month' and 'day' in this format '19850101'. Is there a way to modify this format separating 'year', 'month and 'day'? Thanks.

답변 (1개)

Giuseppe Inghilterra
Giuseppe Inghilterra 2020년 2월 25일
Hi,
you convert to string your time vector (num2str function) and then convert it to date (datetime function), specifying input format as follow:
time1_str = num2str(time1);
time1_date = datetime(time1_str,'InputFormat','yyyyMMdd','Format','dd-MM-yyyy');
Note that you can decide output format (in my example is dd-MM-yyyy).
Hope this helps.
  댓글 수: 2
Valerio Gianforte
Valerio Gianforte 2020년 2월 25일
Thank you so much
Giuseppe Inghilterra
Giuseppe Inghilterra 2020년 2월 25일
Your welcome. If solution/answer works for you, remember to mark answer as accepted.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by