ex11_1.m

来自「《MATLAB程序设计教程》一书的随书源代码」· M 代码 · 共 40 行

M
40
字号
screen=get(0,'ScreenSize');
W=screen(3);H=screen(4);
figure('Color',[1,1,1],'Position',[0.2*H,0.2*H,0.5*W,0.3*H],...
       'Name','图形演示系统','NumberTitle','off','MenuBar','none');
%定义Plot菜单项
hplot=uimenu(gcf,'Label','&Plot');
uimenu(hplot,'Label','Sine Wave','Call',...
['t=-pi:pi/20:pi;','plot(t,sin(t));',...
        'set(hgon,''Enable'',''on'');',...
'set(hgoff,''Enable'',''on'');',...
        'set(hbon,''Enable'',''on'');',...
'set(hboff,''Enable'',''on'');']);
uimenu(hplot,'Label','Cosine Wave','Call',...
['t=-pi:pi/20:pi;','plot(t,cos(t));',...
        'set(hgon,''Enable'',''on'');',...
'set(hgoff,''Enable'',''on'');',...
        'set(hbon,''Enable'',''on'');',...
'set(hboff,''Enable'',''on'');']);
%定义Option菜单项
hoption=uimenu(gcf,'Label','&Option');
hgon=uimenu(hoption,'Label','&Grig on',...
'Call','grid on','Enable','off');
hgoff=uimenu(hoption,'Label','&Grig off',...
'Call','grid off','Enable','off');
hbon=uimenu(hoption,'Label','&Box on',...
'separator','on','Call','box on','Enable','off');
hboff=uimenu(hoption,'Label','&Box off',...
'Call','box off','Enable','off');
hwincor=uimenu(hoption,'Label','&Window Color','Separator','on');
uimenu(hwincor,'Label','&Red','Accelerator','r',...
'Call','set(gcf,''Color'',''r'');');
uimenu(hwincor,'Label','&Blue','Accelerator','b',...
'Call','set(gcf,''Color'',''b'');');
uimenu(hwincor,'Label','&Yellow','Call',...
'set(gcf,''Color'',''y'');');     
uimenu(hwincor,'Label','&White','Call',...
'set(gcf,''Color'',''w'');');     
%定义Quit菜单项
uimenu(gcf,'Label','&Quit','Call','close(gcf)');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?