How can I create a loop using date form ?

Hello,
date=0002042013; end_date=0802042013;
I need to create a loop that starts with the date and finish date in this end_data after running hour by hour!
I thought I would create multiple loops, but that's not very nice, I think there is a specific function but do not know which. I will be very grateful for any help.

댓글 수: 1

Jan
Jan 2013년 4월 17일
It is not clear, what "date=0002042013" exactly means. Number do not have a leading zero, strings need surrounding quotes.

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

 채택된 답변

Leah
Leah 2013년 4월 17일

1 개 추천

Not sure if this is the range you wanted, but you can change start and end date to what you like
start_date='2/04/2013 0:00'; end_date='2/04/2013 8:00';
hr_step=datenum(0,0,0,1,0,0);
%use matlab datenums
date_array=datenum(start_date):hr_step:datenum(end_date);
cellstr(datestr(date_array)) % display in date format
Also, do not use "date" as a variable name. It is a function in matlab to return the current date
date()

댓글 수: 4

Arthur Melo
Arthur Melo 2013년 4월 17일
I was already very happy with the answer. Can I create a loop using this sintax:
for delta_date=datenum(start_date):hr_step:datenum(end_date)
?
Leah
Leah 2013년 4월 17일
yep, that will work
Arthur Melo
Arthur Melo 2013년 4월 18일
Hey, what function I need put before the cellstr to put the date in this form: 0002042013, 0102042013 ?
Leah
Leah 2013년 4월 18일
cellstr(datestr(date_array,'HHmmddyyyy'))
I think that's what you want where HH is the two digit military hour

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Calendar에 대해 자세히 알아보기

태그

질문:

2013년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by