Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: [转载]关税10
发信站: 哈工大紫丁香 (Thu Jun 12 21:27:30 2003)
function gui15(command_str)
if nargin == 0
command_str = 'initialize';
end
global h_box h_grid h_ydata h_xdata h_status
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); % Bring figure to front of screen.
return; % No need to reinitialize, exit function.
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','gui15(''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','gui15(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox');
h_ydata = uicontrol(h_fig,...
'CallBack','gui15(''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','gui15(''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');
gui15('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);
gui15('Set Box');
gui15('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 分析这个关税程序与前一程序有何不同?
2 想一想这个程序可能会有什么问题?
--
╔═══════════════════╗
║★★★★★友谊第一 比赛第二★★★★★║
╚═══════════════════╝
※ 来源:.哈工大紫丁香 bbs.hit.edu.cn [FROM: 202.118.229.92]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.386毫秒