📄 four_way_mva.m
字号:
l2(:,:,i)=pur_int2;
end
handles.simp_sc1=sc1;
handles.simp_sc2=sc2;
handles.simp_l1=l1;
handles.simp_l2=l2;
handles.sc1=sc1;
handles.sc2=sc2;
handles.l1=l1;
handles.l2=l2;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
figure
for i=1:N2;
subplot(2,N2,i)
imagesc(sc2(:,:,i,1));colormap(gray)
subplot(2,N2,i+N2)
plot(l2(:,i,1)), hline(0,'k--')
xlabel(t_var2)
subplot(2,N2,1)
title('Simplisma results of 1st pure images from mode 1','Position',[168 -5 9])
end
set(handles.Min_2p,'string',1);
set(handles.Max_2p,'string',q);
set(handles.Cur_2p,'string',1);
handles.type='Simplisma';
guidata(hObject,handles)
% --- Executes on button press in mcr.
function mcr_Callback(hObject, eventdata, handles)
% hObject handle to mcr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
opt=questdlg('Do you want to apply nonnegativity to Concentrations?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
options.ccon='nonneg';
else
options.ccon='none';
end
opt=questdlg('Do you want to apply nonnegativity to Spectra?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
options.scon='nonneg';
else
options.scon='none';
end
options.display='off';
options.plots='final';
N1=handles.N1;
N2=handles.N2;
l1=handles.pca_l1;
data=handles.data;
[n,m,p,q]=size(data);
for i=1:q
images=data(:,:,:,i);
data1=reshape(images,[n*m p]);
xinit=l1(:,i,:);
c0=reshape(xinit,[N1 p]);
%c0=rand(N1,p);
[c1,s1] = als(data1,c0,options);
close(1)
close(2)
mcr_images1=reshape(c1,[n m N1]);
mcr_int1=s1';
for j=1:N1
sc1(:,:,i,j)=mcr_images1(:,:,j);
l1(:,i,j)=mcr_int1(:,j);
end
end
for i=1:N1
data2=sc1(:,:,:,i);
[n2,m2,p2]=size(data2);
data3=reshape(data2,[n2*m2 p2]);
c0=rand(N2,p2);
[c2,s2] = als(data3,c0,options);
close(1)
close(2)
mcr_images2=reshape(c2,[n2 m2 N2]);
mcr_int2=s2';
sc2(:,:,:,i)=mcr_images2;
l2(:,:,i)=mcr_int2;
end
handles.mcr_sc1=sc1;
handles.mcr_sc2=sc2;
handles.mcr_l1=l1;
handles.mcr_l2=l2;
handles.sc1=sc1;
handles.sc2=sc2;
handles.l1=l1;
handles.l2=l2;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
figure
for i=1:N2;
subplot(2,N2,i)
imagesc(sc2(:,:,i,1));colormap(gray)
subplot(2,N2,i+N2)
plot(l2(:,i,1)), hline(0,'k--')
xlabel(t_var2)
subplot(2,N2,1)
title('MCR results of 1st component images from mode 1','Position',[168 -5 9])
end
set(handles.Min_2p,'string',1);
set(handles.Max_2p,'string',q);
set(handles.Cur_2p,'string',1);
handles.type='MCR';
guidata(hObject,handles)
% --- Executes on button press in Parafac.
function Parafac_Callback(hObject, eventdata, handles)
% hObject handle to Parafac (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);
data2=reshape(data,[n*m, p,q]);
options=parafac('options');
options.constraints{1}.nonnegativity=1;
options.constraints{2}.nonnegativity=1;
options.constraints{3}.nonnegativity=1;
options.display='off';
options.plots='none';
N=inputdlg('Enter the number of components');
N=str2double(N);
model=parafac(data2,N,options);
scores=reshape(model.loads{1},[n m N]);
loads1=model.loads{2};
loads2=model.loads{3};
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
H.Position=[521 187 262 521];
figure (H)
subplot(2,1,1)
plot(loads1)
hline(0,'k--')
axis tight
xlabel(t_var1)
subplot(2,1,2)
plot(loads2)
hline(0,'k--')
axis tight
xlabel(t_var2)
H.Position=[257 186 257 523];
figure(H)
if N<=3
for i=1:N
subplot(N,1,i)
imagesc(scores(:,:,i));colormap(gray)
end
elseif N==4
for i=1:N
subplot(2,2,i)
imagesc(scores(:,:,i));colormap(gray)
end
else
[a,b,c]=size(scores);
im=reshape(scores,[a b 1 c]);
montage(im,colormap(gray))
end
handles.type3='parafac';
handles.parafac_model=model;
handles.scores_parafac=scores;
handles.loads1_parafac=loads1;
handles.loads2_parafac=loads2;
handles.scores3=scores;
handles.loads1_3=loads1;
handles.loads2_3=loads2;
guidata(hObject,handles)
function N_comp_Callback(hObject, eventdata, handles)
% hObject handle to N_comp (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 N_comp as text
% str2double(get(hObject,'String')) returns contents of N_comp as a double
data=handles.data;
sc2=handles.sc2;
l2=handles.l2;
N=str2double(get(hObject,'String')) ;
N1=handles.N1;
N2=handles.N2;
figure
type=handles.type;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
for i=1:N2;
subplot(2,N2,i)
imagesc(sc2(:,:,i,N));colormap(gray)
subplot(2,N2,i+N2)
plot(l2(:,i,N)), hline(0,'k--')
axis tight
xlabel(t_var2)
subplot(2,N2,1)
title(['The ', type ' results of component images #', num2str(N), ' from mode 1'],'Position',[168 -5 9])
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function N_comp_CreateFcn(hObject, eventdata, handles)
% hObject handle to N_comp (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
% --- Executes on slider movement.
function slider5_Callback(hObject, eventdata, handles)
% hObject handle to slider5 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
data=handles.data;
[n,m,p,q]=size(data);
sc1=handles.sc1;
l1=handles.l1;
N1=handles.N1;
step=1/q;
slider_step(1)=step;
slider_step(2)=step;
set(handles.slider5, 'SliderStep', slider_step, 'Max', q, 'Min',0)
i=get(hObject,'Value');
i=round(i);
if i==0
i=1;
elseif i>=q
i=q;
else i=i;
end
C=i;
set(handles.Cur_2p,'string',C);
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
type=handles.type;
figure
for i=1:N1;
subplot(2,N1,i)
imagesc(sc1(:,:,C,i));colormap(gray)
subplot(2,N1,i+N1)
plot(l1(:,C,i)), hline(0,'k--')
axis tight
xlabel(t_var1)
subplot(2,N1,1)
title(['The ',type,' results of images at ', t_var2, ' #' ,num2str(C)],'Position',[99 -5 9])
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function slider5_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function Cur_2p_Callback(hObject, eventdata, handles)
% hObject handle to Cur_2p (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 Cur_2p as text
% str2double(get(hObject,'String')) returns contents of Cur_2p as a double
sc1=handles.sc1;
l1=handles.l1;
N1=handles.N1;
C=str2double(get(hObject,'String')) ;
set(handles.Cur_2p,'string',C);
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
type=handles.type;
figure
for i=1:N1;
subplot(2,N1,i)
imagesc(sc1(:,:,C,i));colormap(gray)
subplot(2,N1,i+N1)
plot(l1(:,C,i)), hline(0,'k--')
xlabel(t_var1)
subplot(2,N1,1)
title(['The ',type,' results of images at ', t_var2, ' #' ,num2str(C)],'Position',[99 -5 9])
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Cur_2p_CreateFcn(hObject, eventdata, handles)
% hObject handle to Cur_2p (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 compN_Callback(hObject, eventdata, handles)
% hObject handle to compN (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 compN as text
% str2double(get(hObject,'String')) returns contents of compN as a double
N1=handles.N1;
sc1=handles.sc1;
l1=handles.l1;
n=str2double(get(hObject,'String')) ;
sc=sc1(:,:,:,n);
[a,b,c]=size(sc);
im=reshape(sc,[a b 1 c]);
type=handles.type;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
H.Position=[299 200 555 514];
figure(H)
montage(im,colormap(gray))
title(['The ', type, ' component images # ', num2str(n), ' from mode 1 as function of ',t_var2],'Position',[216 -7 9])
H2.Position=[860 204 407 510];
figure(H2)
plot(l1(:,:,n))
hline(0,'k--')
x=[1:1:c]';
text=num2str(x);
legend(text,2)
xlabel(t_var1)
title(['The ', type, ' loading # ', num2str(n), ' from mode 1 as function of ',t_var2])
% --- Executes during object creation, after setting all properties.
function compN_CreateFcn(hObject, eventdata, handles)
% hObject handle to compN (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
% --- Executes on button press in close.
function close_Callback(hObject, eventdata, handles)
% hObject handle to close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close all
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
val = get(hObject,'Value');
switch val
case 2
handles.sc1=handles.pca_sc1;
handles.sc2=handles.pca_sc2;
handles.l1=handles.pca_l1;
handles.l2=handles.pca_l2;
handles.type='PCA';
case 3
handles.sc1=handles.simp_sc1;
handles.sc2=handles.simp_sc2;
handles.l1=handles.simp_l1;
handles.l2=handles.simp_l2;
handles.type='Simplisma';
case 4
handles.sc1=handles.mcr_sc1;
handles.sc2=handles.mcr_sc2;
handles.l1=handles.mcr_l1;
handles.l2=handles.mcr_l2;
handles.type='MCR'
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% 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
% --- Executes on button press in mcr_3.
function mcr_3_Callback(hObject, eventdata, handles)
% hObject handle to mcr_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);
N=inputdlg('Enter the number of components');
N=str2double(N);
[scores, load1, load2]=mcr_three_modes(data,N);
handles.scores_mcr3=scores;
handles.loads1_mcr3=load1;
handles.loads2_mcr3=load2;
handles.type='MCR';
guidata(hObject,handles)
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.data;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -