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

📄 da_xcor.m

📁 这是好用的源代码
💻 M
字号:
%
% da_xcor
%
% Programme for plotting cross correlation graphs
%
% Updated to use own cross correlation routine
%
% croscor.m
%
% Specifies the maximum shift as 10% of the data
% size
%

%
% Sort the screen out
%
da_front;

drawnow;
ax1=axes(...
	'Units','pixels',...
	'Position',[50 150 500 250],...
	'Box','on',...
	'Color',[0 0 0],...
	'Visible','on');

%
% Print a title
%
text1=da_text(w1,190,405,250,15,'Cross / Auto correlation plot',[1 1 1],[1 0 0]);


%
% Set up some crap
%
Xlabel('Time lag');
Ylabel('Correlation');
old_val1=1;
old_val2=2;
sl1_value=1;
sl2_value=2;
p_style=0;
[D L]=size(data);
maxshft=round(D*0.1);
tsm=croscor(data(:,sl2_value),data(:,sl1_value),maxshft);
plot(tsm);
Xlabel('Time lag');
Ylabel('Correlation');

[dummy num_pcs]=size(data);

%
% Have a slider to change which pc to plot
%

sl1=uicontrol(w1,...
	'Style','slider',...
	'Position',[50 60 200 20],...
	'Min',1,...
	'Max',num_pcs,...
	'Value',1,...
	'CallBack',[
		'set(sl1_current,''String'',ceil(get(sl1,''Value'')));',...
		'sl1_value=ceil(get(sl1,''Value''));',...
		'if sl1_value ~= old_val1;',...
			'set(sl1_current,''String'',num2str(ceil(sl1_value)));',...
			'[D L]=size(data);',...
			'text2=da_text(w1,210,10,200,15,''Working.... Please wait!'',[1 1 1],[1 0 0]);',...
			'tsm=croscor(data(:,sl2_value),data(:,sl1_value),maxshft);',...
			'plot(tsm);',...
			'old_val1=sl1_value;',...
			'Xlabel(''Time lag'');',...
			'Ylabel(''Correlation'');',...
			'delete(text2);',...
			'[m in]=max(abs(tsm));',...
			'm=max(tsm);',...
			'm2=min(tsm);',...
			'line([in in],[m2*0.9 m*1.1]);',...
		'end;']);

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

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

sl1_max=uicontrol(w1,...
	'Style','text',...
	'Position',[250 60 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(num_pcs));

sl1_title=uicontrol(w1,...
	'Style','text',...
	'Position',[45 85 180 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Select an input variable');


%
% Now draw a slider to define the principal component plotted
% on the y-axis
%
sl2=uicontrol(w1,...
	'Style','slider',...
	'Position',[370 60 200 20],...
	'Min',1,...
	'Max',num_pcs,...
	'Value',sl2_value,...
	'CallBack',[
		'set(sl2_current,''String'',ceil(get(sl2,''Value'')));',...
		'sl2_value=ceil(get(sl2,''Value''));',...
		'if sl2_value ~= old_val2;',...
			'set(sl1_current,''String'',num2str(ceil(sl1_value)));',...
			'text2=da_text(w1,210,10,200,15,''Working.... Please wait!'',[1 1 1],[1 0 0]);',...
			'[D L]=size(data);',...
			'tsm=croscor(data(:,sl2_value),data(:,sl1_value),maxshft);',...
			'plot(tsm);',...
			'Xlabel(''Time lag'');',...
			'Ylabel(''Correlation'');',...
			'delete(text2);',...
			'[m in]=max(abs(tsm));',...
			'm=max(tsm);',...
			'm2=min(tsm);',...
			'line([in in],[m2*0.9 m*1.1]);',...
			'old_val2=sl2_value;',...
		'end;']);

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

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

sl2_max=uicontrol(w1,...
	'Style','text',...
	'Position',[570 60 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(num_pcs));

sl2_title=uicontrol(w1,...
	'Style','text',...
	'Position',[370 85 170 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Select an output variable');


%
% Edit text to define the maximum time lag to consider
%

text3=da_text(w1,140,40,250,15,'Maximum number of timesteps to consider:',[1 1 1],[0 0 1]);

text4=uicontrol(w1,...
	'style','edit',...
	'position',[400 40 50 15],...
	'foregroundcolor',[1 1 1],...
	'backgroundcolor',[1 0 0],...
	'string',num2str(maxshft),...
	'callback',[
		'a=get(text4,''string'');',...
		'a=str2num(a);',...
		'if a ~= [];',...
			'maxshft=a;',...
			'set(text4,''string'',num2str(maxshft));',...
			'text2=da_text(w1,210,10,200,15,''Working.... Please wait!'',[1 1 1],[1 0 0]);',...
			'[D L]=size(data);',...
			'tsm=croscor(data(:,sl2_value),data(:,sl1_value),maxshft);',...
			'plot(tsm);',...
			'Xlabel(''Time lag'');',...
			'Ylabel(''Correlation'');',...
			'delete(text2);',...
			'[m in]=max(abs(tsm));',...
			'm=max(tsm);',...
			'm2=min(tsm);',...
			'line([in in],[m2*0.9 m*1.1]);',...
		'else;',...
			'set(text4,''string'',''maxshft'');',...
		'end']);

⌨️ 快捷键说明

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