Matlab的gui界面设计实例练习
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一个不错的Matlab的gui界面设计实例
%非常漂亮的日历,
function CalendarTable;
% calendar 日历
% Example:
% CalendarTable;
S=datestr(now);
[y,m,d]=datevec(S);
% d is day
% m is month
% y is year
DD={'Sun','Mon','Tue','Wed','Thu','Fri','Sat'};
close all
figure;
for k=1:7;
uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.02+k*0.1,0.55,0.08,0.06],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String',DD(k),'fontsize',16,'fontname','times new roman');
end
h=1;
ss='b';
qq=eomday(y,m);
for k=1:qq;
n=datenum(y,m,k);
[da,w] = weekday(n);
if k==d;
ss='r';
end
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.02+da*0.1,0.55-h*0.08,0.08,0.06],... 'BackgroundColor',0.6*[1,1,1],'ForegroundColor',ss,...
'String',num2str(k));
ss='b';
if da==7;
h=h+1;
end
end
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.6,0.66,0.12,0.08],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor',ss,...
'String','clock','fontsize',18,'fontname','times new roman');
Tq=uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.74,0.66,0.17,0.08],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor',[0.1,0.9,0.9],...
'fontsize',18,'fontname','times new roman');
sq='The calendar';
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.14,0.86,0.37,0.08],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor',[0.1,0.9,0.9],...
'fontsize',18,'fontname','times new roman','string',sq);
try
while 1
set(Tq,'String',datestr(now,13));
pause(1);
end
end
计算万年历的Matlab程序(2008-12-21 13:59:19)
标签:matlab万年历杂谈分类:Matlab实例function test_calendar(year,month)
% 输入年份,月份,打印这个月的月历
run = 0;
ping = 0;
fprintf('\n%s %s %s %s %s %s %s\n',...
'日','一','二','三','四','五','六');
% 计算从第一年到前一年的闰年和平年的个数
for i =1:year-1
if (mod(i,4)==0 & mod(i,100)~=0) | mod(i,400)==0
run = run+1;
else
ping = ping+1;
end
end
% 计算从第一年到当年前一个月的天数sum = 366*run+365*ping;
for i = 1:month-1
sum = sum+monthday(year,i);
end
% 获得这个月的天数
n = monthday(year,month);
temp = zeros(n,1);
sum = sum+1;
% 计算这个月第一天是星期几
wkd = mod(sum,7);
for i = 1:n
temp(wkd+i) = i;
end
l = 1;
m = 1;
% 打印日历
for i = 1:length(temp)
if temp(i) ==0
temp2(l,m) = ' ';
fprintf(' ');
m = m+1;
else
temp2(l,m) = temp(i);
if temp(i) >= 10
fprintf('%d ',temp(i)); else
fprintf('%d ',temp(i)); end
m = m+1;
end
if mod(i,7)==0
fprintf('\n');
m = 1;
l = l+1;