recurrence_plot.m
来自「主成分分析和偏最小二乘SquaresPrincipal成分分析( PCA )和偏」· M 代码 · 共 796 行 · 第 1/2 页
M
796 行
function varargout = recurrence_plot(varargin)
% RECURRENCE_PLOT M-file for recurrence_plot.fig
%
% cross-recurrence:
% RP=recurrence_plot(x,y,gui_mode,norm,treshold,embedding,delay);
% recurrence:
% RP=recurrence_plot(x,gui_mode,norm,treshold,embedding,delay);
% RP=recurrence_plot(x);
% Parameters:
% x,y - data vectors
% gui_mode - 'gui' or 'silent'
% norm - 1- Maximum norm
% 2- Euclidean norm
% 3- Minimum norm
% 4- Fixed amount of nearest neighbours
% 5- Distance coded matrix
% 6- Interdependent neighbours
%
% Example:
% RP=recurrence_plot(x,y,'gui',1,0.1,3,1);
%
% based on N. Marwan's CRP Toolbox
% Last Modified by GUIDE v2.5 19-Jul-2004 20:50:39
% last modified 10.01.05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @recurrence_plot_OpeningFcn, ...
'gui_OutputFcn', @recurrence_plot_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before recurrence_plot is made visible.
function recurrence_plot_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to recurrence_plot (see VARARGIN)
% Choose default command line output for recurrence_plot
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes recurrence_plot wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% RP=recurrence_plot(x,y,gui_mode,norm,treshold,embedding,delay);
global rpGLOBALS
set(handles.norm,'string',{'Maximum norm' 'Euclidean norm' 'Minimum norm' 'Fixed amount of nearest neighbours' 'Distance coded matrix' 'Interdependent neighbours'});
L=length(varargin);
rpGLOBALS.auto=0;
switch L
case 0
error('Not enougth input parameters');
case 1
rpGLOBALS.x=varargin{1};
rpGLOBALS.y=varargin{1};
set(hObject,'name','Recurrence plot');
rpGLOBALS.gui_mode='gui';
if length(rpGLOBALS.y)>1
set([handles.text_embedding, handles.frame_embedding handles.text_dimension...
handles.text_delay handles.edit_delay handles.edit_dimension],'enable','off');
set(handles.ax_graph,'visible','off');
else
axes(handles.ax_graph);
plot(rpGLOBALS.x);
end
case {2; 3; 4; 5; 6; 7}
rpGLOBALS.x=varargin{1};
if isa(varargin{2},'double')
rpGLOBALS.y=varargin{2};
set(hObject,'name','Cross recurrence plot');
rpGLOBALS.gui_mode='gui';
if length(rpGLOBALS.y)~=length(rpGLOBALS.x)
error('Time series must have equal dimensions');
end
axes(handles.ax_graph);
plot(rpGLOBALS.x);
if length(rpGLOBALS.y)>1
set([handles.text_embedding, handles.frame_embedding handles.text_dimension...
handles.text_delay handles.edit_delay handles.edit_dimension],'enable','off');
hold on
axes(handles.ax_graph);
plot(rpGLOBALS.y,'r');
% xlim([]);
hold off
end
if L>2
rpGLOBALS.gui_mode=varargin{3};
end
if L>3
set(handles.norm,'value',varargin{4});
end
if L>4
set(handles.edit_treshold,'string',num2str(varargin{5}));
rpGLOBALS.auto=1;
end
if L>5
set(handles.edit_dimension,'value',varargin{6});
rpGLOBALS.auto=1;
end
if L>6
set(handles.edit_delay,'string',num2str(varargin{7}));
rpGLOBALS.auto=1;
end
else
if strcmp(varargin{2},'gui')||strcmp(varargin{2},'silent')
rpGLOBALS.gui_mode=varargin{2};
else
warning('Unrecognized parameter ''gui_mode''. ''gui_mode'' set to ''gui''');
rpGLOBALS.gui_mode='gui';
end
rpGLOBALS.x=varargin{1};
rpGLOBALS.y=varargin{1};
set(hObject,'name','Recurrence plot');
if length(rpGLOBALS.y)>1
set([handles.text_embedding, handles.frame_embedding handles.text_dimension...
handles.text_delay handles.edit_delay handles.edit_dimension],'enable','off');
set(handles.ax_graph,'visible','off');
else
axes(handles.ax_graph);
plot(rpGLOBALS.x);
end
if L>2
set(handles.norm,'value',varargin{3});
end
if L>3
set(handles.edit_treshold,'string',num2str(varargin{4}));
rpGLOBALS.auto=1;
end
if L>4
set(handles.edit_dimension,'value',varargin{5});
rpGLOBALS.auto=1;
end
if L>5
set(handles.edit_delay,'string',num2str(varargin{6}));
rpGLOBALS.auto=1;
end
end
end
% --- Outputs from this function are returned to the command line.
function varargout = recurrence_plot_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
global rpGLOBALS
if rpGLOBALS.auto
compute_Callback(handles.compute, [], handles);
varargout{1} =rpGLOBALS.RP;
if strcmp(rpGLOBALS.gui_mode,'silent')
try
close(handles.figure1);
catch
end
end
else
uiwait;
try
varargout{1} =rpGLOBALS.RP;
catch
end
end
% try
% close(handles.figure1);
% catch
% end
function compute_Callback(hObject, eventdata, handles)
% hObject handle to compute (see GCBO)
% handles structure with handles and user data (see GUIDATA)
global rpGLOBALS
X=rpGLOBALS.x;
Y=rpGLOBALS.y;
E=str2num(get(handles.edit_treshold,'string'));
Norm=get(handles.norm,'value');
switch Norm
case 1
n='maxnorm';
case 2
n='euclidean';
case 3
n='minnorm';
case 4
n='fan';
case 6
n='inter';
case 5
n='distance';
end
M=get(handles.edit_dimension,'value');
T=str2num(get(handles.edit_delay,'string'));
RP=crp_big(X,Y,M,T,E,n,'sil');
% RP=crp_big(X,Y,1,1,E,n,'sil');
[s1 s2]=size(RP);
RP=rot90(double(RP));
if ~strcmp(n,'distance')
RP=-RP+max(max(RP));
end
RP=ceil(RP./max(max(RP)).*s1);
RP(find(RP==0))=1;
if strcmp(rpGLOBALS.gui_mode,'gui')
axes(handles.ax_plot);
image(RP);
colormap gray;
end
rpGLOBALS.RP=RP;
if ~rpGLOBALS.auto
uiresume;
end
% --- Executes during object creation, after setting all properties.
function norm_CreateFcn(hObject, eventdata, handles)
% hObject handle to norm (see GCBO)
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
set(hObject,'string','Maximum norm|Euclidean norm|Minimum norm|Fixed amount of nearest neighbours|Interdependent neighbours|Distance coded matrix');
% --- Executes on selection change in norm.
function norm_Callback(hObject, eventdata, handles)
% hObject handle to norm (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns norm contents as cell array
% contents{get(hObject,'Value')} returns selected item from norm
if get(hObject,'Value')==5
set(handles.edit_treshold,'enable','off');
else
set(handles.edit_treshold,'enable','on');
end
% --- Executes during object creation, after setting all properties.
function edit_treshold_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_treshold (see GCBO)
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_treshold_Callback(hObject, eventdata, handles)
% hObject handle to edit_treshold (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_treshold as text
% str2double(get(hObject,'String')) returns contents of edit_treshold as a double
function cancel_Callback(hObject, eventdata, handles)
% hObject handle to compute (see GCBO)
% handles structure with handles and user data (see GUIDATA)
global GSD_GLOBALS
GSD_GLOBALS.recurrence_plot=[];
close(gcf);
function edit_delay_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_delay (see GCBO)
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_delay_Callback(hObject, eventdata, handles)
% hObject handle to edit_delay (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_delay as text
% str2double(get(hObject,'String')) returns contents of edit_delay as a double
% --- Executes during object creation, after setting all properties.
function edit_dimension_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_dimension (see GCBO)
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_dimension_Callback(hObject, eventdata, handles)
% hObject handle to edit_dimension (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_dimension as text
% str2double(get(hObject,'String')) returns contents of edit_dimension as a double
V=str2double(get(hObject,'String'));
if V(get(hObject,'value'))>1
set(handles.edit_delay,'enable','on');
else
set(handles.edit_delay,'enable','off');
end
function xout=crp_big(varargin)
%CRP_BIG Creates a cross recurrence plot/ recurrence plot.
% CRP_BIG(X [,Y] [,param1,param2,...]) creates a cross
% recurrence plot/ recurrence plot. Results can be
% stored into the workspace. In contrast to CRP, long
% data series can be used. Results can be stored into
% the workspace.
%
% R=CRP_BIG(X,M,T,E) uses the dimension M, delay T
% and the size of neighbourhood E and creates a recurrence
% plot of X.
%
% R=CRP_BIG(X,Y,'distance','nonormalize') creates a
% distance coded matrix plot without normalization
% of the data.
%
% The source-data X and test-data Y can be one- or
% a two-coloumn vectors (then, in the first column
% have to be the time); if the test-data Y is not
% specified, a simple recurrence plot is created.
%
% Parameters: dimension M, delay T and the size of
% neighbourhood E are the first three numbers after
% the data series; further parameters can be used
% to switch between various methods of finding the
% neighbours of the phasespace trajectory, to suppress
% the normalization of the data and to suppress the
% GUI (useful in order to use this programme by other
% programmes).
%
% Methods of finding the neighbours.
% maxnorm - Maximum norm.
% euclidean - Euclidean norm.
% minnorm - Minimum norm.
% nrmnorm - Euclidean norm between normalized vectors
% (all vectors have the length one).
% fan - Fixed amount of nearest neighbours.
% inter - Interdependent neighbours.
% distance - Distance coded matrix (global CRP, Euclidean norm).
%
% Normalization of the data series.
% normalize - Normalization of the data.
% nonormalize - No normalization of the data.
%
% Parameters not needed to be specified.
%
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?