How to view current time in matlab... Then select the Second's value and use it as an input

2 ビュー (過去 30 日間)
Mahad Aftab
Mahad Aftab 2019 年 11 月 27 日
回答済み: Star Strider 2019 年 11 月 27 日
Hey Everyone.. I want to create a function that If i write "Hey" as input then the function should display head or tail depending upon the current time... If the value of second (in time) is even display head and if odd display tail.

回答 (1 件)

Star Strider
Star Strider 2019 年 11 月 27 日
Two possibilities:
dv = datevec(now);
ht = rem(fix(dv(6)),2);
out = char('head'.*(ht==0) + 'tail'.*(ht==1))
and:
dt = rem(fix(second(datetime('now','Format','ss'))),2);
out = char('head'.*(dt==0) + 'tail'.*(dt==1))
Both give the same result.
Choose the one that best fits your requirements.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by