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

📄 da_trans.m

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 M
字号:
%
% da_trans.m
%
% Transforms data by:
%
%		Taking logs
%		Powers
%		Square roots
%		Exponentials
%

da_front;
drawnow;
w1=gcf;
%
% Put the original data into a backup matrix
%

transd=data;
old_sl2_value=1;
transvar=1;

%
% Radio buttons for data transforms
%

but1=uicontrol(w1,...
	'style','radio',...
	'position',[60 370 200 20],...
	'String','Take logs of this variable',...
	'Foregroundcolor',[1 1 1],...
	'Backgroundcolor',[0 0 0],...
	'Callback',[
		'set(but1,''Value'',1);',...
		'set(but2,''Value'',0);',...
		'set(but3,''Value'',0);']);

but2=uicontrol(w1,...
	'style','radio',...
	'position',[60 340 150 20],...
	'string','Raise to the power n:',...
	'Foregroundcolor',[1 1 1],...
	'Backgroundcolor',[0 0 0],...
	'Callback',[
		'set(but1,''Value'',0);',...
		'set(but2,''Value'',1);',...
		'set(but3,''Value'',0);']);

but3=uicontrol(w1,...
	'style','radio',...
	'position',[60 310 200 20],...
	'string','Take the square root:',...
	'Foregroundcolor',[1 1 1],...
	'Backgroundcolor',[0 0 0],...
	'Callback',[
		'set(but1,''Value'',0);',...
		'set(but2,''Value'',0);',...
		'set(but3,''Value'',1);']);


set(but1,'Value',1);


box1=uicontrol(w1,...
	'style','frame',...
	'position',[50 300 350 110],...
	'foregroundcolor',[1 1 1],...
	'backgroundcolor',[0 0 0]);

%
% Slider for the exponents option
%
% Included up to powers of 5, which should be easily enough
%

sl1=uicontrol(w1,...
	'style','slider',...
	'position',[220 340 100 20],...
	'Min',-5,...
	'Max',5,...
	'Value',2,...
	'CallBack',[
		'set(text1,''String'',[''n = '' num2str(get(sl1,''Value''))]);',...
		'set(but1,''Value'',0);',...
		'set(but2,''Value'',1);',...
		'set(but3,''Value'',0);']);

text1=da_text(w1,335,342,60,15,['n = ' num2str(ceil(get(sl1,'Value')))],[1 1 1],[1 0 0]);


%
% Perform this transform on the current variable button
%

but5=uicontrol(w1,...
	'style','push',...
	'position',[425 360 175 20],...
	'string','Transform current variable',...
	'callback',[
		'if get(but1,''Value'')==1;',...
			'transd(:,transvar)=log(transd(:,transvar));',...
		'elseif get(but2,''Value'')==1;',...
			'transd(:,transvar)=transd(:,transvar).^(ceil(get(sl1,''Value'')));',...
		'elseif get(but3,''Value'')==1;',...
			'transd(:,transvar)=sqrt(transd(:,transvar));',...
		'end;',...
		'axes(ax2);',...
		'plot(transd(:,transvar));',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'set(ax2,''Xlim'',[0 D]);']);

%
% Draw a before and after graph
%

ax1=axes;
set(ax1,...
	'Units','pixels',...
	'Position',[70 100 225 100],...
	'Box','on',...
	'Color',[0 0 0],...
	'Visible','on');

ax2=axes;
set(ax2,...
	'Units','pixels',...
	'Position',[370 100 225 100],...
	'Box','on',...
	'Color',[0 0 0],...
	'Visible','on');

%
% Label these graphs
%

text2=da_text(w1,80,210,150,15,'Before transform:',[1 1 1],[0 0 1]);
text3=da_text(w1,380,210,150,15,'After transform:',[1 1 1],[0 0 1]);

%
% Plot out the initial graphs
%
[D L]=size(transd);
axes(ax1);
plot(data(:,transvar));
set(ax1,'Xlim',[0 D]);
Xlabel('Sample number');
Ylabel('Value');

axes(ax2);
plot(transd(:,transvar));
set(ax2,'Xlim',[0 D]);
Xlabel('Sample number');
Ylabel('Value');

%
% Slider to determine current variable
%

[D L]=size(transd);

sl2=uicontrol(w1,...
	'style','slider',...
	'position',[200 30 175 20],...
	'Min',1,...
	'Max',L,...
	'Value',1,...
	'CallBack',[
		'sl2_value=ceil(get(sl2,''Value''));',...
		'if sl2_value ~= old_sl2_value;',...
			'transvar=sl2_value;',...
			'old_sl2_value=sl2_value;',...
			'axes(ax1);',...
			'plot(data(:,transvar));',...
			'Xlabel(''Sample number'');',...
			'Ylabel(''Value'');',...
			'set(ax1,''Xlim'',[0 D]);',...
			'axes(ax2);',...
			'plot(transd(:,transvar));',...
			'Xlabel(''Sample number'');',...
			'Ylabel(''Value'');',...
			'set(ax2,''Xlim'',[0 D]);',...
			'set(text5,''string'',[''Current = '' num2str(transvar)]);',...
		'end;']);

text4=da_text(w1,50,30,150,15,'Select current variable:',[1 1 1],[0 0 0]);
text5=da_text(w1,275,50,100,15,['Current = ' num2str(transvar)],[1 1 1],[0 0 0]);


%
% Revert to original button
%
but6=uicontrol(w1,...
	'style','push',...
	'position',[425 330 175 20],...
	'string','UNDO all changes',...
	'callback',[
		'transd=data;',...
		'axes(ax1);',...
		'plot(data(:,transvar));',...
		'set(ax1,''Xlim'',[0 D]);',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'axes(ax2);',...
		'plot(transd(:,transvar));',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'set(ax2,''Xlim'',[0 D]);']);



%
% Leave this screen button
%
but7=uicontrol(w1,...
	'style','push',...
	'position',[425 300 175 20],...
	'string','ACCEPT changes',...
	'Callback',[
		'data=transd;',...
		'axes(ax1);',...
		'plot(data(:,transvar));',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'set(ax1,''Xlim'',[0 D]);',...
		'axes(ax2);',...
		'plot(transd(:,transvar));',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'set(ax2,''Xlim'',[0 D]);']);

%
% Shuffle data button
%
but8=uicontrol(w1,...
	'style','push',...
	'position',[425 390 175 20],...
	'string','Shuffle data set',...
	'callback',[
		'transd=shuffle(data);',...
		'axes(ax2);',...
		'plot(transd(:,transvar));',...
		'Xlabel(''Sample number'');',...
		'Ylabel(''Value'');',...
		'set(ax2,''Xlim'',[0 D]);']);

⌨️ 快捷键说明

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