Create a matrix full of dates

Hi!
I need to create a matrix whit dates, starting in a specific date, for example '2013-04-01 22:00:59', and increasing in the interval of my choosing (like 1 sec, 1 min, ...).
I need to define the last one date also.
Could anyone help me?
Thank you in advance

댓글 수: 2

Muthu Annamalai
Muthu Annamalai 2013년 6월 21일
Matrices can store only numbers. However, you can create cell-arrays, and struct-arrays in MATLAB. For example, see, http://www.mathworks.com/help/matlab/matlab_external/create-cell-arrays.html?searchHighlight=cell+array.
Now you can build a date string, using the function, datestr, http://www.mathworks.com/help/matlab/ref/datestr.html?searchHighlight=datestr and you should use the input as your increment time, obtained with the function now()
HTH
JaviOBe
JaviOBe 2013년 6월 21일
Yes sorry I meant that I need to create a cell-array with dates...
What I am doing is geting the first date into my array, and increment it with the interval i want. But I have problems to define this interval...I think it would be an easier solution for this.

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

 채택된 답변

Kelly Kearney
Kelly Kearney 2013년 6월 21일

0 개 추천

If you just want to increment from a fixed point, then that's pretty straightforward.
t0 = datenum('2013-04-01 22:00:59');
dt = 1/(24*60*60); % 1 second
t = datestr(t0 + (1:100)*dt);
Or do you not want the times to increment from the exact start date, but rather something like "increment by 1 hour on the hour" (so for your example, 23:00:00 would be the next, rather than 23:00:59)?

댓글 수: 3

JaviOBe
JaviOBe 2013년 6월 21일
편집: JaviOBe 2013년 6월 21일
No thank you that is exactly what I was looking for. But one more question, how could I acces to a specific date into this vector? Because t(x) do not work...
Leah
Leah 2013년 6월 21일
t = cellstr(datestr(t0 + (1:100)*dt));
or reference t(x,:)
JaviOBe
JaviOBe 2013년 6월 21일
It works thank you!

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

추가 답변 (0개)

카테고리

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