⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 da_filt.m

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 M
字号:
% da_filt.m
%
% Screen to show prefiltered and postfiltered variable and stats
% Calls in appropriate filter function depending upon users choice.
% Written by A. Mitchell (7/12/95)
%
% Calls:	lowpass(alpha,a)
%		browns(alpha,a)
%		bdfilt(alpha,a)
%		bdfiltb(alpha,a)
%		datavala(alpha,a)
%
% where	alpha = filter constant
%		a = prefiltered data
%

clg;
da_front;
drawnow;
w1=gcf;

%
% Draw a set of axes
%
figure(w1);
ax1=axes;
set(ax1,...
	'Units','pixels',...
	'Position',[50 200 500 175],...
	'Box','on',...
	'Color',[0 0 0],...
	'Visible','on');

%
% Initialisation
%
fil_const=0.7;
plot_var=1;
[D L]=size(data);
old_sl1_value=0;
old_sl2_value=0;
sl1_value=1;
sl2_value=0.7;

%
% filter the data
%
if func_typ==1;
   fil_data=lowpass(fil_const,data(:,plot_var));
elseif func_typ==2;
   fil_data=browns(fil_const,data(:,plot_var));
elseif func_typ==3;
   fil_data=bdfilt(fil_const,data(:,plot_var));
   fil_data=fil_data';
elseif func_typ==4;
   fil_data=bdfiltb(fil_const,data(:,plot_var));
   fil_data=fil_data';
else;
   fil_data=datavala(fil_const,data(:,plot_var),D);
   fil_data=fil_data';
end;

%
% Set up a stats box for prefiltered data
%
box1=uicontrol(w1,...
	'style','frame',...
	'position',[50 15 210 105],...
	'foregroundcolor',[0 0 1],...
	'backgroundcolor',[1 1 1]);

%
% Set up text objects in this box
%
text1=da_text(w1,55,100,190,15,['Prefiltered Stats Var.' num2str(plot_var)],[0 0 0],[1 1 1]);
text2=da_text(w1,55,80,190,15,['Minimum value = ' num2str(min(data(:,plot_var)))],[0 0 1],[1 1 1]);
text3=da_text(w1,55,65,190,15,['Maximum value = ' num2str(max(data(:,plot_var)))],[0 0 1],[1 1 1]);
text4=da_text(w1,55,50,190,15,['Standard deviation = ' num2str(std(data(:,plot_var)))],[0 0 1],[1 1 1]);
text5=da_text(w1,55,35,190,15,['Mean value = ' num2str(mean(data(:,plot_var)))],[0 0 1],[1 1 1]);
text12=da_text(w1,55,20,190,15,['Median value = ' num2str(median(data(:,plot_var)))],[0 0 1],[1 1 1]);

%
% Set up a stats box for postfiltered data
%
box2=uicontrol(w1,...
	'style','frame',...
	'position',[350 15 210 105],...
	'foregroundcolor',[0 0 1],...
	'backgroundcolor',[1 1 1]);

%
% Set up text objects in this box
%
text21=da_text(w1,355,100,190,15,['Postfiltered Stats Var.' num2str(plot_var)],[0 0 0],[1 1 1]);
text22=da_text(w1,355,80,190,15,['Minimum value = ' num2str(min(fil_data(:,plot_var)))],[0 0 1],[1 1 1]);
text23=da_text(w1,355,65,190,15,['Maximum value = ' num2str(max(fil_data(:,plot_var)))],[0 0 1],[1 1 1]);
text24=da_text(w1,355,50,190,15,['Standard deviation = ' num2str(std(fil_data(:,plot_var)))],[0 0 1],[1 1 1]);
text25=da_text(w1,355,35,190,15,['Mean value = ' num2str(mean(fil_data(:,plot_var)))],[0 0 1],[1 1 1]);
text212=da_text(w1,355,20,190,15,['Median value = ' num2str(median(fil_data(:,plot_var)))],[0 0 1],[1 1 1]); 

%
% Now plot the variable
%
stairs(data(:,plot_var));
set(ax1,'Xlim',[0 D]);
Xlabel('Sample number');
Ylabel('Value');
hold on;
plot(fil_data,'m');
hold off;

sl1=uicontrol(w1,...
	'style','slider',...
	'position',[390 130 150 20],...
	'Min',1,...
	'Max',L,...
	'Value',1,...
	'CallBack',[
		'set(sl1_current,''String'',ceil(get(sl1,''Value'')));',...
		'sl1_value=ceil(get(sl1,''Value''));',...
		'if sl1_value ~= old_sl1_value;',...
			'set(sl1_current,''String'',num2str(ceil(sl1_value)));',...
			'old_sl1_value=sl1_value;',...
			'plot_var=sl1_value;',...
			'stairs(data(:,plot_var));',...
                        'if func_typ==1;fil_data=lowpass(fil_const,data(:,plot_var));',...
			'elseif func_typ==2;fil_data=browns(fil_const,data(:,plot_var));',...
			'elseif func_typ==3;fil_data=bdfilt(fil_const,data(:,plot_var));',...
               'fil_data=fil_data'';',...
			'elseif func_typ==4;fil_data=bdfiltb(fil_const,data(:,plot_var));',...
               'fil_data=fil_data'';',...
			'else;fil_data=datavala(fil_const,data(:,plot_var),D);',...
               'fil_data=fil_data'';',...
			'end;',...
	                'hold on;',...
                        'plot(fil_data,''m'');',...
                        'hold off;',...
			'Xlabel(''Sample number'');',...
			'Ylabel(''Value'');',...
			'set(ax1,''Xlim'',[0 D]);',...
			'set(text1,''string'',[''Prefiltered Stats Var.'' num2str(plot_var)]);',...
			'set(text2,''string'',[''Minimum value = '' num2str(min(data(:,plot_var)))]);',...
			'set(text3,''string'',[''Maximum value = '' num2str(max(data(:,plot_var)))]);',...
			'set(text4,''string'',[''Standard deviation = '' num2str(std(data(:,plot_var)))]);',...
			'set(text5,''string'',[''Mean value = '' num2str(mean(data(:,plot_var)))]);',...
			'set(text12,''string'',[''Median value = '' num2str(median(data(:,plot_var)))]);',...
			'set(text21,''string'',[''Postfiltered Stats Var.'' num2str(plot_var)]);',...
			'set(text22,''string'',[''Minimum value = '' num2str(min(fil_data))]);',...
			'set(text23,''string'',[''Maximum value = '' num2str(max(fil_data))]);',...
			'set(text24,''string'',[''Standard deviation = '' num2str(std(fil_data))]);',...
			'set(text25,''string'',[''Mean value = '' num2str(mean(fil_data))]);',...
			'set(text212,''string'',[''Median value = '' num2str(median(fil_data))]);',...
		'end;']);

sl1_current=uicontrol(w1,...
	'Style','text',...
	'Position',[530,150,20,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(get(sl1,'Value')));

sl1_min=uicontrol(w1,...
	'Style','text',...
	'Position',[370,130,18,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','1');

sl1_max=uicontrol(w1,...
	'Style','text',...
	'Position',[550,130,25,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(L));

sl1_title=uicontrol(w1,...
	'Style','text',...
	'Position',[380,150,150,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Current variable =');

%
% Draw a slider to change the filter constant
%

sl2=uicontrol(w1,...
	'style','slider',...
	'position',[50 130 150 20],...
	'Min',0,...
	'Max',1,...
	'Value',sl2_value,...
	'CallBack',[
		'set(sl2_current,''String'',ceil(100*(get(sl2,''Value'')))/100);',...
		'sl2_value=ceil(100*(get(sl2,''Value'')))/100;',...
		'if sl2_value ~= old_sl2_value;',...
			'set(sl1_current,''String'',num2str(ceil(sl1_value)));',...
			'old_sl2_value=sl2_value;',...
			'fil_const=sl2_value;',...
			'stairs(data(:,plot_var));',...
                        'if func_typ==1;fil_data=lowpass(fil_const,data(:,plot_var));',...
			'elseif func_typ==2;fil_data=browns(fil_const,data(:,plot_var));',...
			'elseif func_typ==3;fil_data=bdfilt(fil_const,data(:,plot_var));',...
               'fil_data=fil_data'';',...
			'elseif func_typ==4;fil_data=bdfiltb(fil_const,data(:,plot_var));',...
               'fil_data=fil_data'';',...
			'else;fil_data=datavala(fil_const,data(:,plot_var),D);',...
               'fil_data=fil_data'';',...
			'end;',...
	                'hold on;',...
                        'plot(fil_data,''m'');',...
                        'hold off;',...
			'Xlabel(''Sample number'');',...
			'Ylabel(''Value'');',...
			'set(ax1,''Xlim'',[0 D]);',...
			'set(text1,''string'',[''Prefiltered Stats Var.'' num2str(plot_var)]);',...
			'set(text2,''string'',[''Minimum value = '' num2str(min(data(:,plot_var)))]);',...
			'set(text3,''string'',[''Maximum value = '' num2str(max(data(:,plot_var)))]);',...
			'set(text4,''string'',[''Standard deviation = '' num2str(std(data(:,plot_var)))]);',...
			'set(text5,''string'',[''Mean value = '' num2str(mean(data(:,plot_var)))]);',...
			'set(text12,''string'',[''Median value = '' num2str(median(data(:,plot_var)))]);',...
			'set(text21,''string'',[''Postfiltered Stats Var.'' num2str(plot_var)]);',...
			'set(text22,''string'',[''Minimum value = '' num2str(min(fil_data))]);',...
			'set(text23,''string'',[''Maximum value = '' num2str(max(fil_data))]);',...
			'set(text24,''string'',[''Standard deviation = '' num2str(std(fil_data))]);',...
			'set(text25,''string'',[''Mean value = '' num2str(mean(fil_data))]);',...
			'set(text212,''string'',[''Median value = '' num2str(median(fil_data))]);',...
		'end;']);

sl2_current=uicontrol(w1,...
	'Style','text',...
	'Position',[185,150,50,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(get(sl2,'Value')));

sl2_min=uicontrol(w1,...
	'Style','text',...
	'Position',[30,130,18,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','0');

sl2_max=uicontrol(w1,...
	'Style','text',...
	'Position',[220,130,25,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','1');

sl2_title=uicontrol(w1,...
	'Style','text',...
	'Position',[30,150,150,15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Filter Constant =');

%
% Couple more lines of text saying how many variables there are etc
%

text10=da_text(w1,70,400,250,15,['Total number of variables = ' num2str(L)],[1 1 1],[1 0 0]);
text11=da_text(w1,70,380,250,15,['Total number of readings  = ' num2str(D)],[1 1 1],[1 0 0]);

but7=uicontrol(w1,...
	'style','push',...
	'position',[400 380 175 20],...
	'string','ACCEPT changes',...
	'Callback',[
		'data(:,plot_var)=fil_data;',...
		'axes(ax1);']);

⌨️ 快捷键说明

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