How can I create a linspace vector using date commands
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to create a domain for a plot starting from datenum(now) to five days from today with a total of four days in between points.
I am proceding the following way
b = datestr(datenum(now),1)
a = datestr(datenum([0000 00 5]),1)
c = datestr(datenum([0000 00 1]),1)
x = linespace(datestr(b,[a + b],c))
I want MATLAB to output a vector of days starting from now (TODAY) and ending five days from TODAY with a total of four days in beetwen dates (n = 1; on linspace command).
Can you please help?
댓글 수: 0
채택된 답변
Star Strider
2012년 9월 27일
편집: Star Strider
2012년 9월 27일
My approach:
b = datestr(datenum(now),1)
for k1 = 1:6
x(k1) = datenum(addtodate(datenum(b), k1-1, 'day'));
end
x
xs = datestr(x,1)
The x vector are the date numbers to use as your 'XTick' locations. From there, you can either use 'XTick' and 'XTickLabel' or datetick for your x-axis.
댓글 수: 0
추가 답변 (2개)
Azzi Abdelmalek
2012년 9월 27일
편집: Azzi Abdelmalek
2012년 9월 27일
number_day=4
v=datevec(now)
out=datestr(datenum(v(1),v(2),v(3):v(3)+number_day,v(4),v(5),v(6)))
v(1) to incremante ..years
v(2) ...................... months
v(3) .......................days
v(4) ........................hours
v(5) ........................minutes
v(6) ........................secondes
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!