Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: [转载]关税12
发信站: 哈工大紫丁香 (Thu Jun 12 21:28:40 2003)
function gui17(command_str)
if nargin == 0
command_str = 'initialize';
end
if ~strcmp(command_str,'initialize')
h_fig=gcf;
if ~strcmp(get(h_fig,'tag'),'snowdy')
h_figs = get(0,'children');
h_fig=findobj(h_figs,'flat','tag','snowdy');
if(length(h_fig)==0)
gui17('initialize');
return;
end
end
h_box=findobj(h_fig(1),'tag','h_box');
h_grid=findobj(h_fig(1),'tag','h_grid');
h_ydata=findobj(h_fig(1),'tag','h_ydata');
h_xdata=findobj(h_fig(1),'tag','h_xdata');
h_status=findobj(h_fig(1),'tag','h_status');
end
if strcmp(command_str,'initialize')
h_figs = get(0,'children');
h_fig=findobj(h_figs,'flat','tag','snowdy');
if length(h_fig)>0
figure(h_fig(1));
return
end
h_fig=figure('name','Function plotter','tag','snowdy');
fig_exists = 0;
for fig = h_figs'
fig_exists = strcmp(get(fig,'name'),...
'Function Plotter');
if fig_exists
figure(fig);
return;
end
end
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','gui17(''Set Box'');',...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ],...
'tag','h_box');
h_grid = uicontrol(h_fig,...
'CallBack','gui17(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox',...
'tag','h_grid');
h_ydata = uicontrol(h_fig,...
'CallBack','gui17(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit',...
'tag','h_ydata');
h_xdata = uicontrol(h_fig,...
'CallBack','gui17(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit',...
'tag','h_xdata');
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');
gui17('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);
gui17('Set Box');
gui17('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 这里 findobj起什么作用?
2 这里 snowdy标志什么?
--
╔═══════════════════╗
║★★★★★友谊第一 比赛第二★★★★★║
╚═══════════════════╝
※ 来源:.哈工大紫丁香 bbs.hit.edu.cn [FROM: 202.118.229.92]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.324毫秒