📄 correlation_matrix.m
字号:
function varargout = correlation_matrix(varargin)
% -------------------------------------------------------------------------
% this code is part of the 'Reduction Testbench' suite
% developed by A. Manganaro, R. Todeschini, A. Ballabio, D. Mauri
% 2006 - Milano Chemometrics and QSAR Research Group
% -------------------------------------------------------------------------
%
%
% CORRELATION_MATRIX M-file for correlation_matrix.fig
% CORRELATION_MATRIX, by itself, creates a new CORRELATION_MATRIX or raises the existing
% singleton*.
%
% H = CORRELATION_MATRIX returns the handle to a new CORRELATION_MATRIX or the handle to
% the existing singleton*.
%
% CORRELATION_MATRIX('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CORRELATION_MATRIX.M with the given input arguments.
%
% CORRELATION_MATRIX('Property','Value',...) creates a new CORRELATION_MATRIX or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before correlation_matrix_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to correlation_matrix_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% INIT code
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @correlation_matrix_OpeningFcn, ...
'gui_OutputFcn', @correlation_matrix_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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
% --------------------------------------------------------------------
function correlation_matrix_OpeningFcn(hObject, eventdata, handles, varargin)
% Executes just before correlation_matrix is made visible.
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to correlation_matrix (see VARARGIN)
% Choose default command line output for correlation_matrix
handles.output = hObject;
movegui(handles.correlation_matrix,'center');
handles.corr_file = ' ';
handles.corr_mat = ' ';
handles.cur_data = varargin{1};
if isempty(varargin{2})
handles.header_present = 0;
else
handles.cur_headers = varargin{2};
handles.header_present = 1;
end
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function varargout = correlation_matrix_OutputFcn(hObject, eventdata, handles)
% Outputs from this function are returned to the command line.
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function file_edit_CreateFcn(hObject, eventdata, handles)% Executes during object creation, after setting all properties.
% hObject handle to file_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% 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 mat_edit_CreateFcn(hObject, eventdata, handles)
% Executes during object creation, after setting all properties.
% hObject handle to mat_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GUI objects HANDLERS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function file_edit_Callback(hObject, eventdata, handles)% hObject handle to file_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of file_edit as text% str2double(get(hObject,'String')) returns contents of file_edit as a double
% --------------------------------------------------------------------
function mat_edit_Callback(hObject, eventdata, handles)
% hObject handle to mat_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of mat_edit as text
% str2double(get(hObject,'String')) returns contents of mat_edit as a double
% --------------------------------------------------------------------
function save_file_button_Callback(hObject, eventdata, handles)% Executes on button press in save_file_button.
% hObject handle to save_file_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Gets the path and filename from the standard file dialog
[cur_filename,cur_pathname] = uiputfile('corr_mat.txt','Save output as text');
if (cur_filename==0)
cur_corr_file = ' ';
else
cur_corr_file = strcat(cur_pathname,cur_filename);
end
handles.corr_file = cur_corr_file;
set(handles.file_edit,'String',handles.corr_file);
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function save_mat_button_Callback(hObject, eventdata, handles)
% Executes on button press in save_mat_button.
% hObject handle to save_mat_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Gets the path and filename from the standard file dialog
[cur_filename,cur_pathname] = uiputfile('corr_mat.mat','Save output as mat file');
if (cur_filename==0)
cur_corr_file = ' ';
else
cur_corr_file = strcat(cur_pathname,cur_filename);
end
handles.corr_mat = cur_corr_file;
set(handles.mat_edit,'String',handles.corr_mat);
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function cancel_button_Callback(hObject, eventdata, handles)% Executes on button press in cancel_button.
% hObject handle to cancel_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close(handles.correlation_matrix);
% --------------------------------------------------------------------
function mat_checkbox_Callback(hObject, eventdata, handles)
% Executes on button press in mat_checkbox.
% hObject handle to mat_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of mat_checkbox
if (get(hObject,'Value') == get(hObject,'Max'))
set(handles.save_mat_button,'Enable','on');
else
set(handles.save_mat_button,'Enable','off');
end
% --------------------------------------------------------------------
function file_checkbox_Callback(hObject, eventdata, handles)
% Executes on button press in file_checkbox.
% hObject handle to file_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of file_checkbox
if (get(hObject,'Value') == get(hObject,'Max'))
set(handles.save_file_button,'Enable','on');
else
set(handles.save_file_button,'Enable','off');
end
% --------------------------------------------------------------------
function ok_button_Callback(hObject, eventdata, handles)% Executes on button press in ok_button.
% hObject handle to ok_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
if ~(get(handles.file_checkbox,'Value') == get(handles.file_checkbox,'Max')) && ...
~(get(handles.mat_checkbox,'Value') == get(handles.mat_checkbox,'Max'))
warning_box('No output selected');
return;
end
if (get(handles.file_checkbox,'Value') == get(handles.file_checkbox,'Max'))
if strcmp(handles.corr_file,' ')
warning_box('Invalid file for txt output');
return;
end
end
if (get(handles.mat_checkbox,'Value') == get(handles.mat_checkbox,'Max'))
if strcmp(handles.corr_mat,' ')
warning_box('Invalid file for mat output');
return;
end
end
% Calculates the correlation matrix
C = corrcoef(handles.cur_data);
n = size(C);
if (get(handles.file_checkbox,'Value') == get(handles.file_checkbox,'Max'))
try
[file_id mess] = fopen(handles.corr_file, 'wt');
if (file_id==-1)
disp('Error opening the file:');
disp(mess);
return;
end
fprintf(file_id,'Correlation matrix, %dx%d\n\n',n);
for i=1:n
for j=1:n
fprintf(file_id,'%+1.3f\t',C(i,j));
end
fprintf(file_id,'\n');
end
fclose(file_id);
catch
fclose('all');
end
end
if (get(handles.mat_checkbox,'Value') == get(handles.mat_checkbox,'Max'))
save(handles.corr_mat,'C');
end
close (handles.correlation_matrix);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Other code
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function warning_box(cur_msg)
% Calls the msgbox function to show a warning
% cur_msg message string
msgbox({cur_msg});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -