Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: [转载]关税11
发信站: 哈工大紫丁香 (Thu Jun 12 21:28:05 2003)
function gui16(command_str)
if nargin == 0
command_str = 'initialize';
end
if ~strcmp(command_str,'initialize')
handles=get(gcf,'userdata');
h_box=handles(1);
h_grid=handles(2);
h_ydata=handles(3);
h_xdata=handles(4);
h_status=handles(5);
end
if strcmp(command_str,'initialize')
h_figs = get(0,'children');
fig_exists = 0;
for fig = h_figs'
fig_exists = strcmp(get(fig,'name'),...
'Function Plotter');
if fig_exists
figure(fig);
return;
end
end
h_fig = figure('name','Function Plotter');
axes('position',[.07 .5 .86 .4])
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0 0 1 0.4 ],...
'Style','frame');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[0.08 0.05 0.84 0.11 ],...
'Style','frame' );
h_box = uicontrol(h_fig,...
'CallBack','gui16(''Set Box'');',...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ]);
h_grid = uicontrol(h_fig,...
'CallBack','gui16(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox');
% Create the edit boxes for the x data.
h_ydata = uicontrol(h_fig,...
'CallBack','gui16(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit');
h_xdata = uicontrol(h_fig,...
'CallBack','gui16(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit');
h_status = uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.1 0.07 0.8 0.07 ],...
'String','Status Window',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.3 0.15 0.07 ],...
'String','x =',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.2 0.15 0.07 ],...
'String','y(x) =',...
'Style','text');
handles = [h_box h_grid h_ydata h_xdata h_status];
set(h_fig,'userdata',handles);
gui16('Plot Function');
elseif strcmp(command_str,'Set Box')
boxstatus = get(h_box,'value');
if boxstatus == 0;
set(gca,'box','off');
else
set(gca,'box','on');
end
set(h_status,'string',...
['The box property is ' get(gca,'box')]);
elseif strcmp(command_str,'Set Grid')
gridstatus = get(h_grid,'value');
if gridstatus == 0
grid off
else;
grid on
end
set(h_status,'string',...
['The grid is ' get(gca,'xgrid')]);
elseif strcmp(command_str,'Plot Function')
err_ind = 0;
eval(['x = ' get(h_xdata,'string') ';'],'err_ind=1;');
if err_ind == 0;
eval(['y = ' get(h_ydata,'string') ';'],'err_ind=2;');
end
if err_ind == 0
plot(x,y);
gui16('Set Box');
gui16('Set Grid');
set(h_status,'string','Function Plotted');
elseif err_ind == 1
set(h_status,'string','Error defining x');
elseif err_ind == 2
set(h_status,'string','Error defining y(x)');
end
end
练习:
1 分析这个关税程序与灌水15有何不同?
2 为何这个程序更安全一些?
--
╔═══════════════════╗
║★★★★★友谊第一 比赛第二★★★★★║
╚═══════════════════╝
※ 来源:.哈工大紫丁香 bbs.hit.edu.cn [FROM: 202.118.229.92]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.450毫秒