【MATLAB100个实用小技巧】——界面设计(44-55)

前言

🌏MATLAB是一个功能强大的软件,我们可以利用MATLAB进行绘图、算法验证、仿真实验等等。在学习MATLAB的过程中,繁多的命令与代码往往容易使我们脑容量过载😭😭😭请添加图片描述
🌏本系列将总结一些常见的MATLAB编程小技巧😽😽
🌏可能有些地方会有些错误或者是不太完善的,还请大家在评论区直接指出❤️❤️❤️

系列文章

【MATLAB100个实用小技巧】——图形应用(1-10)
【MATLAB100个实用小技巧】——图形应用(11-20)
【MATLAB100个实用小技巧】——图形应用(21-32)
【MATLAB100个实用小技巧】——界面设计(33-43)
【MATLAB100个实用小技巧】——界面设计(44-55)
【MATLAB100个实用小技巧】——界面设计(56-66)
【MATLAB100个实用小技巧】——图形处理(67-75)
【MATLAB100个实用小技巧】——图形处理(76-84)
【MATLAB100个实用小技巧】——数值分析(85-100)

44. 改变坐标轴范围

😉代码

h0 = figure('ToolBar','none','Position',[150 250 500 400],'name','Curve of sinandcos()');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','on'); 
e1=uicontrol('parent',h0,...
'style','edit',...
'string',1,...
'position',[50 120 50 20]);
t1=uicontrol('parent',h0,...
'style','text',...
'string','X 轴最小值',... 
'position',[35 150 80 20]);
e2=uicontrol('parent',h0,... 
    'style','edit',...
'string',5,...
'position',[50 60 50 20]);
t2=uicontrol('parent',h0,...
'style','text',...
'string','X 轴最大值',...
'position',[35 90 80 20]); 
e3=uicontrol('parent',h0,...
'style','edit',...
'string',1,...
'position',[150 120 50 20]); 
t3=uicontrol('parent',h0,...
'style','text',...
'string','Y 轴最小值',... 
'position',[135 150 80 20]);
e4=uicontrol('parent',h0,...
    'style','edit',...
'string',5,...
'position',[150 60 50 20]);
t4=uicontrol('parent',h0,...
    'style','text',...
'string','Y 轴最大值',... 
'position',[135 90 80 20]);
e5=uicontrol('parent',h0,... 
    'style','edit',...
'string',20,... 
'position',[250 120 50 20]);
t5=uicontrol('parent',h0,...
    'style','text',... 
    'horizontalalignment','left',...
    'string',' 点 数 ',...
    'position',[250 150 30 20]);
b1=uicontrol('parent',h0,...
    'style','pushbutton',...
'string','绘图',...
'position',[250 60 60 40],...
'callback',[...
'a=str2num(get(e1,''string''));,',...
'b=str2num(get(e2,''string''));,',...
'c=str2num(get(e3,''string''));,',...
'd=str2num(get(e4,''string''));,',...
'n=str2num(get(e5,''string''));,',...
'xgrid=linspace(-abs(a),abs(a),n);,',...
'ygrid=linspace(-abs(b),abs(b),n);,',...
'[x,y]=meshgrid(xgrid,ygrid);,',...
'z=c*sqrt(d-y.*y/b/b-x.*x/a/a);,',... 
'u=1;,',...
'z1=real(z);,',...
'for k=2:n-1,',...
'for j=2:n-1,',...
'if imag(z(k,j))~=0,',...
'z1(k,j)=0;,',... 
'end,',...
'if all(imag(z([k-1:k+1],[j-1:j+1])))~=0,',... 
'z1(k,j)=nan;,',...
'end,',...
'end,',...
'end,',... 
'surf(x,y,z1),',... 
'hold on,',...
'if u==1,',...
'z2=-z1;,',...
'surf(x,y,z2),',...
'axis([-abs(a),abs(a),-abs(b),abs(b),-abs(c),abs(c)]);,',... 
'end,',...
'xlabel(''x'');,',...
'ylabel(''y'');,',...
'zlabel(''z'');,',...
'hold off']);
b2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'string','关闭',...
'position',[150 10 60 20],...
'callback','close');

😊效果
在这里插入图片描述

45. 简单运算器

😉代码

h1=uicontrol(gcf,'style','radio',...
'string','加',...
'value',1,...
'position',[20 150 40 20],...
'callback',[...
'k=1;,',...
'set(h1,''value'',1),',...
'set(h2,''value'',0),',...
'set(h3,''value'',0)']);
h2=uicontrol(gcf,'style','radio',...
'string','减',...
'position',[20 110 40 20],...
'callback',[...
'k=2;,',...
'set(h2,''value'',1),',...
'set(h1,''value'',0),',...
'set(h3,''value'',0)']);
h3=uicontrol(gcf,'style','radio',...
'string','乘',...
'position',[20 70 40 20],...
'callback',[...
'k=3;,',...
'set(h3,''value'',1),',...
'set(h2,''value'',0),',...
'set(h1,''value'',0)']);
e1=uicontrol(gcf,'style','edit',... 
    'position',[80 150 100 20]);
e2=uicontrol(gcf,'style','edit',... 
    'position',[80 110 100 20]);
e3=uicontrol(gcf,'style','edit',...
    'position',[80 70 100 20]);
b1=uicontrol(gcf,'style','pushbutton',...
    'string','运算',...
'position',[200 150 80 30],...
'callback',[...
'x=str2num(get(e1,''string''));,',...
'y=str2num(get(e2,''string''));,',... 
'switch k,',...
'case 1,',...
'z=x+y;,',...
'case 2,',...
'z=x-y;,',...
'case 3,',...
'z=x*y;,',...
'end,',... 
'set(e3,''string'',num2str(z))']);

b2=uicontrol(gcf,'style','pushbutton',... 
    'string','退出',...
'position',[200 100 80 30],...
'callback','close');

😊效果
在这里插入图片描述

46. 曲线色彩的修改

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','my second gui');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','on'); 
x=0:0.1:2*pi; 
k=plot(x,sin(x));
xlabel('自变量 X');
ylabel('函数值 Y');
title('图形色彩改变'); 
p1=uicontrol('parent',h0,...
'style','pushbutton',...
'backgroundcolor','r',...
'position',[60 100 50 30],... 
'callback','set(k,''color'',''r'')');
p2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'backgroundcolor','g',...
'position',[170 100 50 30],...
'callback','set(k,''color'',''g'')'); 
p3=uicontrol('parent',h0,...
'style','pushbutton',...
'backgroundcolor','b',...
'position',[280 100 50 30],...
'callback','set(k,''color'',''b'')');
p4=uicontrol('parent',h0,...
'style','pushbutton',...
'backgroundcolor',[1 1 1],...
'fontsize',20,...
'fontweight','demi',...
'string','关闭',...
'position',[150 30 80 60],...
'callback','close'); 
t1=uicontrol('parent',h0,...
'style','text',...
'string','红色',...
'fontsize',12,...
'fontweight','demi',... 
'position',[60 120 50 20]);
t2=uicontrol('parent',h0,... 
    'style','text',...
'string','绿色',...
'fontsize',12,...
'fontweight','demi',... 
'position',[170 120 50 20]);
t3=uicontrol('parent',h0,... 
    'style','text',...
'string','蓝色',...
'fontsize',12,...
'fontweight','demi',... 
'position',[280 120 50 20]);

😊效果
在这里插入图片描述

47. 曲线标记

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','my second gui');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','on'); 
x=0:0.1:2*pi; 
k=plot(x,sin(x),'*');
xlabel('自变量 X');
ylabel('函数值 Y');
title('标记类型的改变'); 
p1=uicontrol('parent',h0,...
'style','pushbutton',...
'string','+',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[60 100 50 20],... 
'callback','set(k,''marker'',''+'')');
p2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'string','o',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[170 100 50 20],...
'callback','set(k,''marker'',''o'')'); 
p3=uicontrol('parent',h0,...
'style','pushbutton',...
'string','x',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[280 100 50 20],...
'callback','set(k,''marker'',''x'')');
p4=uicontrol('parent',h0,...
'style','pushbutton',...
'backgroundcolor',[1 1 1],...
'fontsize',20,...
'fontweight','demi',...
'string','关闭',...
'position',[150 30 80 60],...
'callback','close');
t1=uicontrol('parent',h0,...
'style','text',...
'string','星号',...
'fontsize',12,...
'fontweight','demi',... 
'position',[60 120 50 20]);
t2=uicontrol('parent',h0,... 
    'style','text',...
'string','圆圈',...
'fontsize',12,...
'fontweight','demi',... 
'position',[170 120 50 20]);
t3=uicontrol('parent',h0,... 
    'style','text',...
'string','叉号',...
'fontsize',12,...
'fontweight','demi',... 
'position',[280 120 50 20]);

😊效果
在这里插入图片描述

48. 修改曲型

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 48');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','on'); 
x=0:0.1:2*pi;
k=plot(x,sin(x));
xlabel('自变量 X');
ylabel('函数值 Y');
title(' 线 型 的 改 变 '); 
p1=uicontrol('parent',h0,...
'style','pushbutton',...
'string','-.',... 
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[60 100 50 20],... 
'callback','set(k,''linestyle'',''-.'')');
p2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'string',':',... 
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[170 100 50 20],...
'callback','set(k,''linestyle'','':'')'); 
p3=uicontrol('parent',h0,...
'style','pushbutton',...
'string','-',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[280 100 50 20],...
'callback','set(k,''linestyle'',''-'')');
p4=uicontrol('parent',h0,...
'style','pushbutton',...
'backgroundcolor',[1 1 1],...
'fontsize',20,...
'fontweight','demi',...
'string','关闭',...
'position',[150 30 80 60],...
'callback','close'); 
t1=uicontrol('parent',h0,...
'style','text',...
'string','点划线',...
'fontsize',12,...
'fontweight','demi',... 
'position',[60 120 50 20]);
t2=uicontrol('parent',h0,... 
    'style','text',...
'string','虚线',...
'fontsize',12,...
'fontweight','demi',... 
'position',[170 120 50 20]);
t3=uicontrol('parent',h0,... 
    'style','text',...
'string','实线',...
'fontsize',12,...
'fontweight','demi',... 
'position',[280 120 50 20]);

😊效果
在这里插入图片描述

49. 指定坐标轴范围

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 49');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','on'); 
x=0:0.1:2*pi;
y=sin(x);
plot(x,y);
xlabel('X');
ylabel('Y');
title('坐标轴范围的改变'); 
h=get(gca,'xlim');
k=get(gca,'ylim');
e1=uicontrol('parent',h0,...
'style','edit',... 
'string',eval(num2str(h(1))),... 
'horizontalalignment','right',... 
'position',[80 120 100 20]);
t1=uicontrol('parent',h0,... 
    'style','text',...
'string','X 轴最小值',... 
'position',[100 145 80 20]);
e2=uicontrol('parent',h0,...
    'style','edit',... 
    'string',eval(num2str(h(2))),...
    'horizontalalignment','right',... 
    'position',[80 60 100 20]);
t2=uicontrol('parent',h0,... 
    'style','text',...
'string','X 轴最大值',... 
'position',[100 85 80 20]);
e3=uicontrol('parent',h0,... 
    'style','edit',...
'string',eval(num2str(k(1))),... 
'horizontalalignment','right',... 
'position',[250 120 100 20]);
t3=uicontrol('parent',h0,... 
    'style','text',...
'string','Y 轴最小值',... 
'position',[270 145 80 20]);
e4=uicontrol('parent',h0,... 
    'style','edit',... 
    'string',eval(num2str(k(2))),... 
    'horizontalalignment','right',... 
    'position',[250 60 100 20]);
t4=uicontrol('parent',h0,... 
    'style','text',...
'string','X 轴最小值',... 
'position',[270 85 80 20]);
p1=uicontrol('parent',h0,... 
    'style','pushbutton',...
'string','设置',...
'position',[105 10 50 30],...
'callback',[...
'a=str2num(get(e1,''string''));,',...
'b=str2num(get(e2,''string''));,',...
'c=str2num(get(e3,''string''));,',...
'd=str2num(get(e4,''string''));,',... 
'axis([a b c d]),',...
'drawnow']); 
p2=uicontrol('parent',h0,...
'style','pushbutton',...
'string','关闭',...
'position',[275 10 50 30],...
'callback','close');

😊效果
在这里插入图片描述

50. 绘制不同函数曲线的用户界面

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 50');
h1=axes('parent',h0,... 
    'position',[0.29 0.45 0.7 0.5],...
'visible','on');
f=uicontrol('parent',h0,...
'style','frame',...
'position',[5 50 90 400]);
p1=uicontrol('parent',h0,...
'style','pushbutton',...
'position',[150 100 60 40],...
'string','绘图',...
'callback',[...
'm=str2num(get(e1,''string''));,',...
'n=str2num(get(e2,''string''));,',...
'a=get(l1,''value'');,',... 
'x=m:0.1:n;',...
'if a==1,',...
'plot(x,sin(x)),',... 
'end,',...
'if a==2,',...
'plot(x,cos(x)),',... 
'end,',...
'if a==3,',...
'plot(x,exp(x)),',... 
'end']);
p2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'position',[270 100 60 40],...
'string','关闭',...
'callback','close'); 
l1=uicontrol('parent',h0,... 
    'style','listbox',...
'position',[10 300 80 80],... 
'string','sin(x)|cos(x)|exp(x)',... 
'value',1,...
'max',0.5,...
'min',0); f2=uicontrol('parent',h0,...
'style','text',...
'string','选择函数',...
'fontsize',10,... 
'position',[10 380 80 20]);
r1=uicontrol('style','radio',...
'string','grid on',...
'value',0,...
'position',[10 100 60 20],...
'callback',[...
'grid on,',... 
'set(r1,''value'',1);,',...
'set(r2,''value'',0)']);
r2=uicontrol('style','radio',...
'string','grid off',...
'position',[10 80 60 20],...
'value',1,...
'callback',[...
'grid off,',... 
'set(r2,''value'',1);,',...
'set(r1,''value'',0)']); 
e1=uicontrol('parent',h0,...
'style','edit',...
'string',0,...
'position',[20 210 60 20],... 
'horizontalalignment','right');
e2=uicontrol('parent',h0,... 
    'style','edit',...
'string','3',...
'position',[20 150 60 20],... 
'horizontalalignment','right');
t1=uicontrol('parent',h0,... 
    'style','text',...
'string','X from',...
'fontsize',10,...
'position',[20 230 60 20],... 
'horizontalalignment','center');
t2=uicontrol('parent',h0,... 
    'style','text',...
'string','To',...
'fontsize',10,...
'position',[20 170 60 20],... 
'horizontalalignment','center');

😊效果
在这里插入图片描述

51. 可设置函数曲线图视角的用户界面

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 51');
h1=axes('parent',h0,... 
    'position',[0.15 0.45 0.7 0.5],...
'visible','off'); 
[x,y]=meshgrid(-8:0.5:8);
r=sqrt(x.^2+y.^2)+eps; 
z=sin(r)./r;
f1=surf(x,y,z); 
shading interp;
view(-50,30);
camlight left;
colormap([1 0 0])
fv=get(h0,'colormap');
ifv=fv;
p1=uicontrol('parent',h0,...
'style','pushbutton',...
'string','重置',...
'position',[280 120 50 30],...
'callback',[...
'set(s1,''value'',ifv(1));,',...
'set(s2,''value'',ifv(2));,',...
'set(s3,''value'',ifv(3));,',...
'set(h0,''colormap'',ifv)']); 
p2=uicontrol('parent',h0,...
'style','pushbutton',...
'string','关闭',...
'position',[280 60 50 30],...
'callback','close'); 
s1=uicontrol('parent',h0,... 
'style','slider',...
'min',0,...
'max',1,...
'value',fv(1),...
'position',[20 150 200 20],...
'callback',[...
's1k=get(s1,''value'');,',...
'fv(1)=s1k;,',...
'set(h0,''colormap'',fv);']);
t1=uicontrol('parent',h0,...
'style','text',...
'string','改变红色成分',...
'position',[20 170 100 20]);
s2=uicontrol('parent',h0,... 
    'style','slider',...
'min',0,...
'max',1,...
'value',fv(2),...
'position',[20 100 200 20],...
'callback',[...
's2k=get(s2,''value'');,',... 
'fv(2)=s2k;,',...
'set(h0,''colormap'',fv);']);
t2=uicontrol('parent',h0,...
'style','text',...
'string','改变绿色成分',... 
'position',[20 120 100 20]);
s3=uicontrol('parent',h0,...
    'style','slider',...
'min',0,...
'max',1,...
'value',fv(3),...
'position',[20 50 200 20],...
'callback',[...
's3k=get(s3,''value'');,',...
'fv(3)=s3k;,',...
'set(h0,''colormap'',fv);']); 
t1=uicontrol('parent',h0,...
'style','text',...
'string','改变蓝色成分',... 
'position',[20 70 100 20]);

😊效果
在这里插入图片描述

52. 可设置函数曲线图视角的用户界面

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 52');
h1=axes('parent',h0,... 
    'position',[0.15 0.5 0.7 0.5],...
'visible','off'); 
[x,y]=meshgrid(-8:0.5:8);
r=sqrt(x.^2+y.^2)+eps;
z=sin(r)./r;
fh=surf(x,y,z);
shading interp; 
view([-60 30])
fv=get(h1,'view');
fv2=fv;
camlight left ;
sh1=uicontrol('parent',h0,...
'style','slider',...
'max',1,...
'min',-1,...
'value',fv(1)/180,...
'position',[20 150 200 20],...
'callback',[...
'fv(1)=90*get(sh1,''value'');,',...
'set(h1,''view'',[fv(1) fv(2)]),',...
'set(ed1,''string'',fv(1))']); 
text1=uicontrol('parent',h0,...
'style','text',...
'string','方位角的变化滑标',...
'position',[20 170 200 20]); 
sh2=uicontrol('parent',h0,...
'style','slider',...
'max',1,...
'min',-1,...
'value',fv(2)/180,...
'position',[20 90 200 20],...
'callback',[...
'fv(2)=90*get(sh2,''value'');,',...
'set(h1,''view'',[fv(1) fv(2)]),',...
'set(ed2,''string'',fv(2))']); 
text2=uicontrol('parent',h0,...
'style','text',...
'string','仰角的变化滑标',...
'position',[20 110 200 20]);
ed1=uicontrol('parent',h0,... 
    'style','edit',...
'string',fv(1),...
'position',[30 30 50 20]); 
text3=uicontrol('parent',h0,...
'style','text',...
'string','方位角的数值',...
'position',[20 50 80 20]); 
ed2=uicontrol('parent',h0,...
'style','edit',...
'string',fv(2),... 
'position',[150 30 50 20]);
text4=uicontrol('parent',h0,... 
    'style','text',...
'string','仰角的数值',... 
'position',[135 50 80 20]);
pf1=uicontrol('parent',h0,... 
    'style','pushbutton',...
'string','重置',...
'position',[280 120 50 30],...
'callback',[...
'set(h1,''view'',fv2),',...
'set(sh1,''value'',fv2(1)/180),',...
'set(sh2,''value'',fv2(2)/180),',...
'set(ed1,''string'',fv2(1)),',...
'set(ed2,''string'',fv2(2))']);
pf2=uicontrol('parent',h0,...
'style','pushbutton',...
'string','关闭',...
'position',[280 60 50 30],...
'callback','close');

😊效果
在这里插入图片描述

53. 可设置函数曲线光源的用户界面

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 53');
h1=axes('parent',h0,... 
    'position',[0.15 0.5 0.7 0.5],...
'visible','off'); 
[x,y]=meshgrid(-8:0.5:8);
r=sqrt(x.^2+y.^2)+eps;
z=sin(r)./r;
fh=surf(x,y,z); 
shading interp;
view([-60 30]);
camlight left;
lightk=light('position',[0 -2 1]); 
button1=uicontrol('parent',h0,...
'style','pushbutton',...
'string','设置光线',...
'position',[80 60 70 30],...
'callback',[...
'an1=inputdlg(''光线来源的 X 轴坐标'');,',...
'k1=str2num(an1{1});,',...
'an2=inputdlg(''光线来源的 Y 轴坐标'');,',...
'k2=str2num(an2{1});,',...
'an3=inputdlg(''光线来源的 Z 轴坐标'');,',...
'k3=str2num(an3{1});,',... 
'set(lightk,''position'',[k1 k2 k3]);,',...
'set(edit1,''string'',[''['',num2str(k1),'' '',num2str(k2),'' '',num2str(k3),'']'']);']); 
button2=uicontrol('parent',h0,...
'style','pushbutton',...
'string','关闭',...
'position',[250 60 70 30],...
'callback','close');
edit1=uicontrol('parent',h0,...
'style','edit',...
'max',2,...
'min',0,...
'fontsize',15,...
'backgroundcolor',[1 1 1],...
'string','[0 -2 1]',...
'position',[80 110 220 30]);

text1=uicontrol('parent',h0,... 
    'style','text',...
'backgroundcolor',[0.75 0.75 0.75],... 
'fontsize',15,...
'string','光线来源坐标',... 
'position',[80 140 220 30]);

😊效果
在这里插入图片描述

54. 添加效果

😉代码

h0=figure('toolbar','none',...
'position',[200 50 300 350],...
'name','实例 54');
h1=axes('parent',h0,...
    'position',[0.2 0.4 0.6 0.6],...
'visible','off'); 
ezsurf('sin(sqrt(x.^2+y.^2))/sqrt(x.^2+y.^2)',[-6*pi,6*pi]);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','设置',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[40 50 50 20],...
'callback',[...
'view(0,75);,',...
'shading interp;,',... 
'lightangle(-45,30);,',...
'k=findobj(gca,''type'',''surface'');,'...
'set(k,''facelighting'',''phong'');,',...
'set(k,''ambientstrength'',0.3);,',...
'set(k,''diffusestrength'',0.8);,',...
'set(k,''specularstrength'',0.9);,',...
'set(k,''specularexponent'',25);,',...
'set(k,''backfacelighting'',''unlit'')']); 
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','关闭',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[120 50 50 20],...
'callback','close');

😊效果
在这里插入图片描述

55. 查询日期

😉代码

h0=figure('toolbar','none',...
'position',[198 56 408 468],...
'name','实例 55');
h1=axes('parent',h0,... 
    'position',[0.15 0.5 0.7 0.5],...
'visible','off');
huidiao=[...
'yearnum=str2num(get(edit1,''string''));,',...
'monthnum=str2num(get(edit2,''string''));,',...
'daynum=str2num(get(edit3,''string''));,',... 
'monthday=[0 31 28 31 30 31 30 31 31 30 31 30 31];,',...
'dyear=yearnum-2000;,',...
'beishu=fix(dyear/4);,',...
'yushu=rem(yearnum,4);,',...
'if yushu==0,',...
'monthday(3)=29;,',... 
'end,',...
'mday=0;,',...
'for i=1:monthnum,',...
'mday=monthday(i)+mday;,',... 
'end,',...
'yearday=mday+daynum-1;,',...
'noweek=fix(yearday/7);,',...
'set(edit5,''string'',[''第'',num2str(noweek),''周'']);,',... 
'if dyear>0,',...
'if yushu==0,',...
'beishu=beishu-1;,',...
'end,',... 
'dday=yearday+365*dyear+beishu+1;,',... 
'end,',...
'if dyear<=0,',... 
'dday=365*dyear+yearday+beishu;,',... 
'end,',...
'mweek=rem(dday,7)+7;,',... 
'if mweek==8,',...
'set(edit4,''string'',''Sunday'');,',...
'end,',...
'if mweek==9,',...
'set(edit4,''string'',''Monday'');,',... 
'end,',...
'if mweek==10,',... 
'set(edit4,''string'',''Tuesday'');,',...
'end,',...
'if mweek==11,',...
'set(edit4,''string'',''Wednesday'');,',...
'end,',...
'if mweek==12,',...
'set(edit4,''string'',''Thursday'');,',...
'end,',...
'if mweek==13,',... 
'set(edit4,''string'',''Friday'');,',...
'end,',...
'if mweek==7,',... 
'set(edit4,''string'',''Saturday'');,',... 
'end,',...
'if mweek==6,',... 
'set(edit4,''string'',''Friday'');,',...
'end,',...
'if mweek==5,',...
'set(edit4,''string'',''Thursday'');,',...
'end,',...
'if mweek==4,',...
'set(edit4,''string'',''Wednesday'');,',...
'end,',...
'if mweek==3,',...
'set(edit4,''string'',''Tuesday'');,',...
'end,',...
'if mweek==2,',... 
'set(edit4,''string'',''Monday'');,',... 
'end,',...
'if mweek==1,',... 
'set(edit4,''string'',''Sunday'');,',... 
'end'];
edit1=uicontrol('parent',h0,... 
    'style','edit',... 
    'horizontalalignment','right',... 
    'position',[40 300 50 20]);
text1=uicontrol('parent',h0,... 
    'style','text',...
'string',' 年 ',... 
'horizontalalignment','left',... 
'position',[90 300 50 20]);
edit2=uicontrol('parent',h0,...
    'style','edit',... 
    'horizontalalignment','right',... 
    'position',[160 300 50 20]);

text2=uicontrol('parent',h0,... 
    'style','text',...
'string',' 月 ',... 
'horizontalalignment','left',... 
'position',[210 300 50 20]);
edit3=uicontrol('parent',h0,... 
    'style','edit',... 
    'horizontalalignment','right',... 
    'position',[280 300 50 20]);
text3=uicontrol('parent',h0,... 
    'style','text',...
'string',' 日 ',... 
'horizontalalignment','left',... 
'position',[330 300 50 20]);
edit4=uicontrol('parent',h0,... 
    'style','edit',... 
    'horizontalalignment','left',... 
    'position',[210 200 120 20]);
text4=uicontrol('parent',h0,... 
    'style','text',...
'string','查找的日期为',... 
'horizontalalignment','right',... 
'position',[110 200 100 20]);
edit5=uicontrol('parent',h0,... 
    'style','edit',... 
    'horizontalalignment','left',... 
    'position',[210 100 120 20]);
text1=uicontrol('parent',h0,... 
    'style','text',...
'string',' 该 日 处 于 ',... 
'horizontalalignment','left',... 
'position',[160 100 50 20]);
button1=uicontrol('parent',h0,... 
    'style','pushbutton',...
'position',[80 40 80 30],...
'string','开始',... 
'callback',huidiao);
button2=uicontrol('parent',h0,... 
    'style','pushbutton',...
'position',[220 40 80 30],...
'string','关闭',...
'callback','close');

😊效果
在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuan〇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值