您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > Matlab的gui界面设计实例练习
一个不错的Matlab的gui界面设计实例%非常漂亮的日历,functionCalendarTable;%calendar日历%Example:%CalendarTable;S=datestr(now);[y,m,d]=datevec(S);%disday%mismonth%yisyearDD={'Sun','Mon','Tue','Wed','Thu','Fri','Sat'};closeallfigure;fork=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','timesnewroman');endh=1;ss='b';qq=eomday(y,m);fork=1:qq;n=datenum(y,m,k);[da,w]=weekday(n);ifk==d;ss='r';enduicontrol(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';ifda==7;h=h+1;endenduicontrol(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','timesnewroman');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','timesnewroman');sq='Thecalendar';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','timesnewroman','string',sq);trywhile1set(Tq,'String',datestr(now,13));pause(1);endend计算万年历的Matlab程序(2008-12-2113:59:19)标签:matlab万年历杂谈分类:Matlab实例functiontest_calendar(year,month)%输入年份,月份,打印这个月的月历run=0;ping=0;fprintf('\n%s%s%s%s%s%s%s\n',...'日','一','二','三','四','五','六');%计算从第一年到前一年的闰年和平年的个数fori=1:year-1if(mod(i,4)==0&mod(i,100)~=0)|mod(i,400)==0run=run+1;elseping=ping+1;endend%计算从第一年到当年前一个月的天数sum=366*run+365*ping;fori=1:month-1sum=sum+monthday(year,i);end%获得这个月的天数n=monthday(year,month);temp=zeros(n,1);sum=sum+1;%计算这个月第一天是星期几wkd=mod(sum,7);fori=1:ntemp(wkd+i)=i;endl=1;m=1;%打印日历fori=1:length(temp)iftemp(i)==0temp2(l,m)='';fprintf('');m=m+1;elsetemp2(l,m)=temp(i);iftemp(i)=10fprintf('%d',temp(i));elsefprintf('%d',temp(i));endm=m+1;endifmod(i,7)==0fprintf('\n');m=1;l=l+1;endendfprintf('\n');%闰年和平年每月的天数functionout=monthday(year,i)ifmod(year,4)==0&mod(year,100)~=0|mod(year,400)==0data=[312931303130313130313031];elsedata=[312831303130313130313031];endout=data(i);举例:输入:test_calendar(2008,12)返回:日一二三四五六12345678910111213141516171819202122232425262728293031闲来无事,学了一些MatlabGUI的基础知识,想找个东西练一下手。看中了windows的日期与时间显示面板,于是依葫芦画瓢,用Matlab做了一个,嘿嘿,觉得还挺像模像样的。下面是效果图。今日进一步完成了农历的计算和显示。
本文标题:Matlab的gui界面设计实例练习
链接地址:https://www.777doc.com/doc-5841635 .html