📄 zhuchengfen_window.m
字号:
% 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
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (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 checkbox2
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject handle to checkbox3 (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 checkbox3
% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject handle to checkbox4 (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 checkbox4
% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject handle to checkbox5 (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 checkbox5
% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject handle to checkbox7 (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 checkbox7
% --- Executes on button press in checkbox7.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject handle to checkbox7 (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 checkbox7
% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject handle to checkbox9 (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 checkbox9
% --- Executes on button press in checkbox9.
function checkbox10_Callback(hObject, eventdata, handles)
% hObject handle to checkbox9 (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 checkbox9
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%打开并读取数据文件
%说明YSData是全局变量
global YSData;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[filename,pathname,FILTERINDEX]=uigetfile({'*.txt';'*.dat';'*.*'},'选择数据文件');
if(FILTERINDEX==0)
return;
end
str_filename=[pathname,filename];
fid=fopen(str_filename,'rt');
if(fid==-1)
errordlg('Open file error!','Open error');
return;
end
mn=fscanf(fid,'%f,%f',2);
temp=textscan(fid,'%f','returnOnError',0);
YSData=vec2mat(temp{1},mn(2));
%只有正确打开数据文件时,才能激活‘开始分析’按钮
set(handles.pushbutton2,'Enable','on');
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%进行主成分分析
%说明YSData是全局变量
global YSData;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%判断‘数据标准化’下组合框中的各单选按钮的选中情况,并存储在Index_radiobutton中
Index_radiobutton=get([handles.radiobutton1,handles.radiobutton2,...
handles.radiobutton3,handles.radiobutton4,...
handles.radiobutton5,handles.radiobutton6,...
handles.radiobutton7],'Value');
%进行总和标准化
if(Index_radiobutton{1}==1)
SUMData=sum(YSData);
[n,m]=size(YSData);
BZHData=YSData./SUMData(ones(n,1),:);
%进行最大值标准化
elseif(Index_radiobutton{2}==1)
MAXData=max(YSData);
[n,m]=size(YSData);
BZHData=YSData./MAXData(ones(n,1),:);
%进行模标准化
elseif(Index_radiobutton{3}==1)
MOData=sqrt(sum(YSData.^2));
[n,m]=size(YSData);
BZHData=YSData./MOData(ones(n,1),:);
%进行中心标准化
elseif(Index_radiobutton{4}==1)
MEANData=mean(YSData);
[n,m]=size(YSData);
BZHData=YSData-MEANData(ones(n,1),:);
%进行标准差标准化
elseif(Index_radiobutton{5}==1)
BZCData=std(YSData);
[n,m]=size(YSData);
BZHData=YSData./BZCData(ones(n,1),:);
%进行级差标准化
elseif(Index_radiobutton{6}==1)
MEANData=mean(YSData);
[n,m]=size(YSData);
TempData1=YSData-MEANData(ones(n,1),:);
Temp=minmax(YSData');
TempData2=(Temp(:,2)-Temp(:,1))';
BZHData=TempData1./TempData2(ones(n,1),:);
%进行级差正规化
elseif(Index_radiobutton{7}==1)
MINData=min(YSData);
[n,m]=size(YSData);
TempData1=YSData-MINData(ones(n,1),:);
Temp=minmax(YSData');
TempData2=(Temp(:,2)-Temp(:,1))';
BZHData=TempData1./TempData2(ones(n,1),:);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%判断是否用标准化后的数据进行主成分分析
if(get(handles.checkbox1,'Value')==1)
[PC,SCORE,latent,tsquare]=princomp(BZHData);
else
[PC,SCORE,latent,tsquare]=princomp(YSData);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%判断‘参数设置’下组合框中的各单选按钮的选中情况,并对编辑框中输入数据的合理性进行判断
Index_radiobutton=get([handles.radiobutton8,handles.radiobutton9],'Value');
if(Index_radiobutton{1}==1)
percent=str2num(get(handles.edit1,'String'));
isempty(percent)
if(percent<=0|percent>1)
msgbox('填写的数据必须在0和1之间','数据错误','error','modal');
return;
elseif(isempty(percent))
msgbox('填写的数据不能为空','数据错误','error','modal');
return;
end
elseif(Index_radiobutton{2}==1)
number=round(str2num(get(handles.edit2,'String')));
if(number<1|number>m)
msgbox('填写的数据必须是0和变量数之间的整数','数据错误','error','modal');
return;
elseif(isempty(number))
msgbox('填写的数据不能为空','数据错误','error','modal');
return;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%判断‘输出数据’下组合框中的各复选按钮的选中情况,并存储在Index_checkbox中
Index_checkbox=get([handles.checkbox2,handles.checkbox3,...
handles.checkbox4,handles.checkbox5,...
handles.checkbox6,handles.checkbox7,...
handles.checkbox8,handles.checkbox9],'Value');
%数据输出%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%输出主成分系数矩阵
if(Index_checkbox{1}==1)
coefficient=PC(:,1:number);
end
%输出主成分得分系数
if(Index_checkbox{2}==1)
score_num=SCORE(:,1:number);
end
%输出载荷矩阵
if(Index_checkbox{3}==1)
temp1=latent(1:number)';
temp2=temp1(ones(m,1),:).^0.5;
compmat=coefficient.*temp2;
end
%输出主成分贡献率向量
if(Index_checkbox{4}==1)
temp1=100*latent/sum(latent)';
offer=temp1(1:number)';
end
%图形输出%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%如果图形输出的四个复选框中只要有一个被选中,那么就建立一个绘图窗体
if(Index_checkbox{5}==1|Index_checkbox{6}==1|Index_checkbox{7}==1|Index_checkbox{8}==1)
figure('Name','图形输出','MenuBar','none','NumberTitle','off');
end
%在绘图窗体左上角绘制各主成分贡献率直方图
if(Index_checkbox{5}==1)
subplot(221);
pareto(offer);
title('各主成分贡献率直方图');
end
%在绘图窗体右上角绘制方差贡献散点图
if(Index_checkbox{6}==1)
subplot(222);
plot(latent,'r+');
title('方差贡献散点图');
end
%在绘图窗体左下角绘制方差贡献山麓图
if(Index_checkbox{7}==1)
subplot(223);
plot(latent,'g-');
title('方差贡献山麓图');
end
%在绘图窗体右下角绘制前两个主成分散点图
if(Index_checkbox{8}==1&str2num(get(handles.edit2,'String'))>=2)
subplot(224);
plot(score_num(:,1),score_num(:,2),'+');
title('前两个主成分散点图');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%恢复程序开始时各控件的状态
set(handles.radiobutton8,'Value',1);
set(handles.radiobutton9,'Value',0);
set(handles.edit1,'Enable','on');
set(handles.edit2,'Enable','off','String','');
set(handles.checkbox2,'Value',1);
set(handles.checkbox3,'Value',1);
set(handles.checkbox4,'Value',1);
set(handles.checkbox5,'Value',1);
set(handles.checkbox6,'Value',1);
set(handles.checkbox7,'Value',1);
set(handles.checkbox8,'Value',1);
set(handles.checkbox9,'Value',1);
set(handles.radiobutton1,'Enable','on','Value',0);
set(handles.radiobutton2,'Enable','on','Value',0);
set(handles.radiobutton3,'Enable','on','Value',0);
set(handles.radiobutton4,'Enable','on','Value',0);
set(handles.radiobutton5,'Enable','on','Value',1);
set(handles.radiobutton6,'Enable','on','Value',0);
set(handles.radiobutton7,'Enable','on','Value',0);
set(handles.checkbox1,'Value',1);
set(handles.pushbutton2,'Enable','off');
set(handles.edit1,'String','0.8');
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%关闭程序
close;
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%帮助信息
msgbox('skdjflskdj','Test msgbox','help','modal');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -