How can I create a datetick using if statements?

2 ビュー (過去 30 日間)
jjlivestrong
jjlivestrong 2012 年 9 月 21 日
I am trying to create datetick variables to be plotted in the x-axis of a curve.
The code I am trying to create must start with the time of 7:00 am wich I am going to asign the variable TODAY. The magnitude of TODAY must extend from 7:00 am to 12:00 pm, and then switch to another variable, REST_OF_TODAY that extends from 12:00 pm to 5:00 pm.
Basically what I was thinking of is somekind of if statement that when the datetick function reaches the 12:00 pm value switch the variable name from TODAY to REST_OF_TODAY.
TODAY = 7:00 am - 12:00 pm
REST_OF_TODAY = 12:00 pm - 5:00 pm
Can you please help?
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
how many plots ?
jjlivestrong
jjlivestrong 2012 年 9 月 21 日
One plot only.

サインインしてコメントする。

採用された回答

Matt Tearle
Matt Tearle 2012 年 9 月 21 日
編集済み: Matt Tearle 2012 年 9 月 21 日
Do you actually want to create a variable that has two states or is this just about how you visualize a time series? If it's the latter, you can easily just adjust the axis properties
x = linspace(7,17);
plot(x,sin(sqrt(x)*pi))
set(gca,'XTick',[7,12],'XTickLabel',{'Today','Rest of today'})
Or, if time is given in terms of date numbers:
t1 = datenum([2012 9 21 7 0 0]) % 7 am today
t2 = datenum([2012 9 21 17 0 0]) % 5 pm
x = linspace(t1,t2);
plot(x,sin(sqrt(x-t0)*pi))
set(gca,'XTick',[t1,floor(t1)+0.5],'XTickLabel',{'Today','Rest of today'})

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
編集済み: Azzi Abdelmalek 2012 年 9 月 21 日
TODAY = 7/24 : 1/(24):12/24; %or TODAY=12/24 :1/(24): 17/24
plot(TODAY ,rand(1,6))
set(gca,'xtick',TODAY)
datetick('x','keepticks')

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by