matlab 日历仿真,matlab绘制实用日历实例代码

function TheStudy;%函数名

close all;%关闭所有床头

DD={‘Sun‘,‘Mon‘,‘Tue‘,‘Wed‘,‘Thu‘,‘Fri‘,‘Sat‘};%日历表头文字

figure;%打开一个窗口

%绘制窗口中的图标

uicontrol(gcf,‘style‘,‘text‘,‘unit‘,‘normalized‘,‘position‘,[0.12,0.9,0.4,0.08],...

‘ForegroundColor‘,[0.4,0.9,0.8],‘BackgroundColor‘,[0.3,0.4,0.4],‘fontsize‘,21,‘String‘,‘The Calendar‘);

td=uicontrol(gcf,‘style‘,‘push‘,‘unit‘,‘normalized‘,...

‘position‘,[0.22,0.1,0.5,0.1],‘fontname‘,‘default‘,...

‘fontsize‘,18,‘ForegroundColor‘,0.6*[1,1,1],‘BackgroundColor‘,‘r‘);

%绘制日历的表头

for k=1:7

uicontrol(gcf,‘style‘,‘text‘,‘unit‘,‘normalized‘,...

‘position‘,[0.02+k*0.1,0.7,0.08,0.06],‘fontsize‘,18,...

‘ForegroundColor‘,‘r‘,‘BackgroundColor‘,‘b‘,‘String‘,DD{k});

end

%取出现在时间的字符串

timestr=datestr(now);

%时间付给年 月 日

[y,m,d]=datevec(timestr);

%本月的总天数

last=eomday(y,m);

%---------

%以下四行为求月初是星期几的算法。

%总结出来的规律

%假设目前为星期 x(1<=x<=7),日期号为d.

%得y=x+1+7-rem(d,7);

%∴本月初为星期z=rem(y,7)+1;

number_week=weekday(timestr);

remvalue=rem(d,7);

number_week=number_week+7-remvalue;

number_week=rem(number_week,7)+1;

row=0;

total_num=0;%记录画上图标的天数,不超过本月总天数(last)

bc=‘b‘;

while total_num

total_num=total_num+1;

if total_num==d

bc=‘r‘;

else

bc=‘w‘;

end

uicontrol(gcf,‘style‘,‘push‘,‘ForegroundColor‘,bc,‘BackgroundColor‘,0.4*[1,1,1],...

‘String‘,num2str(total_num),‘fontsize‘,18,‘fontname‘,‘default‘,‘unit‘,‘normalized‘,...

‘position‘,[0.02+number_week*0.1,0.6-row*0.08,0.08,0.06]);

if number_week==7

row=row+1;

number_week=1;

else

number_week=number_week+1;

end

end

try%循环显示当前时间

while 1

[y,m,d,h,mi,s]=datevec(datestr(now));

set(td,‘String‘,[datestr(now,2),‘ ‘,datestr(now,13)]);

pause(1);

end

end

执行结果:

20181004141100683912.jpg

原文:http://www.cnblogs.com/sytu/p/4294481.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值