bfm_plot_brain_scores.m
来自「绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX」· M 代码 · 共 1,467 行 · 第 1/3 页
M
1,467 行
end
grp_rows = [];
% num_groups = length(datamat_files);
num_groups = length(num_subj_lst);
load(SessionProfiles{1}{1}, 'session_info'); % get cond info
conditions = session_info.condition;
if exist('bscan','var') & ~isempty(bscan)
selected_conditions = find(cond_selection);
selected_conditions = selected_conditions(bscan);
cond_selection = zeros(1,length(cond_selection));
cond_selection(selected_conditions) = 1;
end
selected_conditions = cond_selection;
if isempty(selected_conditions)
selected_conditions = ones(1,length(conditions));
end
for i=1:num_groups
% grp_rows = [grp_rows, session_info.num_subjects*sum(selected_conditions)];
% grp_rows = [grp_rows, num_subj_lst(i)*session_info.num_conditions];
grp_rows = [grp_rows, num_subj_lst(i)*sum(selected_conditions)];
end
session_info.num_subjects = num_subj_lst(1);
session_info.subj_name = subj_name;
% selected_conditions = ones(1,length(conditions));
num_cond_lst = ones(1,length(num_subj_lst)).*num_conditions;
setappdata(gcf,'selected_conditions',selected_conditions);
setappdata(gcf,'session_info',session_info);
setappdata(gcf,'behavname',behavname);
setappdata(gcf,'behavdata',behavdata);
setappdata(gcf,'brainscores',brainscores);
setappdata(gcf,'num_subj_lst',num_subj_lst);
setappdata(gcf, 'grp_rows', grp_rows);
num_group = length(num_subj_lst);
popup_list = cell(1,num_group);
for i=1:num_group
popup_list{i} = sprintf('[ Group #%d ]',i);
end;
popup_h = findobj(gcf,'Tag','STDatamatPopup');
set(popup_h,'String',popup_list, ...
'HorizontalAlignment', 'left','Value',1);
set(gcf,'Pointer',old_pointer);
return; % load_pls_brainscores
%--------------------------------------------------------------------------
%
function status = get_brain_scores
status = 0;
h = findobj(gcf,'Tag','STDatamatPopup');
popup_string = get(h,'String');
selected_idx = get(h,'Value');
selected_data = popup_string{selected_idx};
last_datamat = getappdata(gcf,'PlottedDatamat');
% if (isempty(last_datamat) | strcmp(last_datamat,selected_data) == 0)
if(1)
setappdata(gcf,'PlottedDatamat',selected_data);
set(findobj(gcf,'Tag','MessageLine'),'String','');
else
status = 2;
return;
end;
% datamat_file = getappdata(gcf,'datamat_filename');
% datamat_file = datamat_file{selected_idx}.fullname;
% load(datamat_file, 'selected_conditions', ...
% 'session_info'); % load the condition from session profile
% setappdata(gcf,'session_info',session_info);
% setappdata(gcf,'selected_conditions',selected_conditions);
setappdata(gcf,'selected_idx',selected_idx);
status = 1;
return; % get_brain_scores
%--------------------------------------------------------------------------
%
function plot_brain_scores(choice)
status = get_brain_scores;
if (status ~= 1);
return;
end;
lv = getappdata(gcf, 'CurrLVState');
detail_state = getappdata(gcf,'PlotDetailState');
allerr_state = getappdata(gcf,'PlotAllerrState');
dlv_state = getappdata(gcf,'PlotDLVState');
brainscores = getappdata(gcf, 'brainscores');
num_subj_lst = getappdata(gcf, 'num_subj_lst');
behavdata = getappdata(gcf, 'behavdata');
behavname = getappdata(gcf, 'behavname');
selected_conditions = getappdata(gcf, 'selected_conditions');
session_info = getappdata(gcf, 'session_info');
grp_rows = getappdata(gcf,'grp_rows');
selected_idx = getappdata(gcf,'selected_idx');
[r c]=size(brainscores);
numscans = sum(selected_conditions);
numbehav = size(behavdata, 2);
numsubj = num_subj_lst(selected_idx);
numlvs = c;
lv = find(lv);
for behav=1:numbehav
first = sum(grp_rows(1:selected_idx))-grp_rows(selected_idx)+1;
last = first+numsubj-1;
for scan=1:numscans
p1 = polyfit(behavdata(first:last,behav), ...
brainscores(first:last,lv), 1);
linc_wave(:,behav,scan) = polyval(p1, behavdata(first:last,behav));
brain_wave(:,1,scan) = brainscores(first:last,lv);
behav_wave(:,behav,scan) = behavdata(first:last,behav);
strong = corrcoef(behavdata(first:last,behav), ...
brainscores(first:last,lv) );
strong_r(1,behav,scan) = strong(1,2);
first = first +numsubj; %scans are stacked, so increment
last = last +numsubj;
end
end
first = numscans*numbehav*(selected_idx-1)+1;
last = first+numscans*numbehav-1;
boot_result = getappdata(gcf,'boot_result');
lvcorrs = getappdata(gcf,'lvcorrs');
if isempty(boot_result)
% set(findobj('tag','BrainMenu'),'visible','off');
% set(findobj('tag','ErrorMenu'),'visible','off');
plotted_data.orig_corr = lvcorrs(first:last,lv);
plotted_data.ulcorr = [];
plotted_data.llcorr = lvcorrs(first:last,lv);
else
plotted_data.orig_corr = boot_result.orig_corr(first:last,lv);
plotted_data.ulcorr = boot_result.ulcorr(first:last,lv);
plotted_data.llcorr = boot_result.llcorr(first:last,lv);
end
plotted_data.linc_wave = linc_wave;
plotted_data.brain_wave = brain_wave;
plotted_data.behav_wave = behav_wave;
plotted_data.behavname = behavname;
plotted_data.strong_r = strong_r;
condition.cond_name = session_info.condition(find(selected_conditions));
% wrong labelling % not for bfm/fmri
% condition.cond_name = session_info.condition(selected_conditions);
first = sum(num_subj_lst(1:selected_idx))-num_subj_lst(selected_idx)+1;
last = first+numsubj-1;
condition.subj_name = session_info.subj_name(first:last);
h = findobj(gcf,'Tag','PlotButton');
if strcmp(lower(get(h,'Enable')),'off'), return; end;
% generate the plots
%
plot_cond_idx = [1:numscans];
plot_dims = getappdata(gcf,'PlotDims');
if isempty(plot_dims)
if (numscans < 1)
num_rows = numscans;
else
num_rows = 1;
end;
if (numbehav < 1),
num_cols = numbehav;
else
num_cols = 1;
end;
plot_dims = [num_rows num_cols];
end;
axes_margin = [.25 .05 .18 .05];
pet_detail_hdl = [];
pet_allerr_hdl = [];
pet_dlv_hdl = [];
h0 = gcf;
pet_plot_cond_stim_ui('STARTUP', plotted_data, condition, ...
axes_margin, plot_dims, plot_cond_idx);
if detail_state
pet_detail_hdl = ...
pet_plot_detail_stim_ui('STARTUP', plotted_data, condition, ...
axes_margin, plot_dims, plot_cond_idx, 'Brain Scores');
setappdata(pet_detail_hdl,'main_fig',h0);
setappdata(h0,'pet_detail_hdl',pet_detail_hdl);
pet_allerr_hdl = getappdata(h0,'pet_allerr_hdl');
if ~isempty(pet_allerr_hdl) & ishandle(pet_allerr_hdl)
setappdata(pet_detail_hdl,'pet_allerr_hdl',pet_allerr_hdl);
end
pet_dlv_hdl = getappdata(h0,'pet_dlv_hdl');
if ~isempty(pet_dlv_hdl) & ishandle(pet_dlv_hdl)
setappdata(pet_detail_hdl,'pet_dlv_hdl',pet_dlv_hdl);
end
end
if allerr_state
pet_allerr_hdl = pet_plot_allerr;
setappdata(pet_allerr_hdl,'main_fig',h0);
setappdata(h0,'pet_allerr_hdl',pet_allerr_hdl);
pet_detail_hdl = getappdata(h0,'pet_detail_hdl');
if ~isempty(pet_detail_hdl) & ishandle(pet_detail_hdl)
setappdata(pet_allerr_hdl,'pet_detail_hdl',pet_detail_hdl);
end
pet_dlv_hdl = getappdata(h0,'pet_dlv_hdl');
if ~isempty(pet_dlv_hdl) & ishandle(pet_dlv_hdl)
setappdata(pet_allerr_hdl,'pet_dlv_hdl',pet_dlv_hdl);
end
end
if dlv_state
pet_dlv_hdl = pet_plot_behavlv;
setappdata(pet_dlv_hdl,'main_fig',h0);
setappdata(h0,'pet_dlv_hdl',pet_dlv_hdl);
pet_detail_hdl = getappdata(h0,'pet_detail_hdl');
if ~isempty(pet_detail_hdl) & ishandle(pet_detail_hdl)
setappdata(pet_dlv_hdl,'pet_detail_hdl',pet_detail_hdl);
end
pet_allerr_hdl = getappdata(h0,'pet_allerr_hdl');
if ~isempty(pet_allerr_hdl) & ishandle(pet_allerr_hdl)
setappdata(pet_dlv_hdl,'pet_allerr_hdl',pet_allerr_hdl);
end
end
if exist('choice','var') & strcmp(choice,'detail') & detail_state
figure(pet_detail_hdl);
elseif exist('choice','var') & strcmp(choice,'allerr') & allerr_state
figure(pet_allerr_hdl);
elseif exist('choice','var') & strcmp(choice,'dlv') & dlv_state
figure(pet_dlv_hdl);
else
figure(h0);
end
setappdata(gcf,'BfMRI_PLOT_BS_ACTIVE',1);
setappdata(gcf,'PLS_BS_PLOTTED_DATA',plotted_data);
setappdata(gcf,'PLS_BS_PLOTTED_CONDITON',condition);
setappdata(gcbf,'pet_detail_hdl',pet_detail_hdl);
setappdata(gcbf,'pet_allerr_hdl',pet_allerr_hdl);
setappdata(gcbf,'pet_dlv_hdl',pet_dlv_hdl);
return;
%--------------------------------------------------------------------------
%
function ToggleBrain
brain_state = getappdata(gcf,'PlotBrainState');
switch (brain_state)
case {0}
m_hdl = findobj(gcf,'Tag','BrainMenu');
set(m_hdl,'Label','Hide Brain Scores Plot');
setappdata(gcf,'PlotBrainState',1);
m_hdl = findobj(gcf,'Tag','ErrorMenu');
set(m_hdl,'Label','Show Correlation Plot');
setappdata(gcf,'PlotErrorState',0);
set(findobj('tag','ChgPlotDims'),'visible','on');
m_hdl = findobj(gcf,'Tag','LegendMenu');
set(m_hdl,'Label','&Show Legend','userdata',0,'visible','off');
case {1}
m_hdl = findobj(gcf,'Tag','BrainMenu');
set(m_hdl,'Label','Show Brain Scores Plot');
setappdata(gcf,'PlotBrainState',0);
m_hdl = findobj(gcf,'Tag','ErrorMenu');
set(m_hdl,'Label','Hide Correlation Plot');
setappdata(gcf,'PlotErrorState',1);
set(findobj('tag','ChgPlotDims'),'visible','off');
m_hdl = findobj(gcf,'Tag','LegendMenu');
set(m_hdl,'Label','&Hide Legend','userdata',1,'visible','on');
end
plot_brain_scores;
return;
%--------------------------------------------------------------------------
%
function ToggleError
error_state = getappdata(gcf,'PlotErrorState');
switch (error_state)
case {1}
m_hdl = findobj(gcf,'Tag','BrainMenu');
set(m_hdl,'Label','Hide Brain Scores Plot');
setappdata(gcf,'PlotBrainState',1);
m_hdl = findobj(gcf,'Tag','ErrorMenu');
set(m_hdl,'Label','Show Correlation Plot');
setappdata(gcf,'PlotErrorState',0);
set(findobj('tag','ChgPlotDims'),'visible','on');
m_hdl = findobj(gcf,'Tag','LegendMenu');
set(m_hdl,'Label','&Show Legend','userdata',0,'visible','off');
case {0}
m_hdl = findobj(gcf,'Tag','BrainMenu');
set(m_hdl,'Label','Show Brain Scores Plot');
setappdata(gcf,'PlotBrainState',0);
m_hdl = findobj(gcf,'Tag','ErrorMenu');
set(m_hdl,'Label','Hide Correlation Plot');
setappdata(gcf,'PlotErrorState',1);
set(findobj('tag','ChgPlotDims'),'visible','off');
m_hdl = findobj(gcf,'Tag','LegendMenu');
set(m_hdl,'Label','&Hide Legend','userdata',1,'visible','on');
end
plot_brain_scores;
return;
%--------------------------------------------------------------------------
%
function ToggleDetail
detail_state = getappdata(gcf,'PlotDetailState');
switch (detail_state)
case {1}
m_hdl = findobj(gcf,'Tag','DetailMenu');
set(m_hdl,'Label','Show &Brain Scores Overview');
setappdata(gcf,'PlotDetailState',0);
pet_detail_hdl = getappdata(gcf,'pet_detail_hdl');
if exist('pet_detail_hdl','var') & ishandle(pet_detail_hdl)
try
delete(pet_detail_hdl);
catch
end
end
case {0}
m_hdl = findobj(gcf,'Tag','DetailMenu');
set(m_hdl,'Label','Hide &Brain Scores Overview');
setappdata(gcf,'PlotDetailState',1);
plot_brain_scores('detail');
end
return;
%--------------------------------------------------------------------------
%
function ToggleDLV
dlv_state = getappdata(gcf,'PlotDLVState');
switch (dlv_state)
case {1}
m_hdl = findobj(gcf,'Tag','DLVMenu');
set(m_hdl,'Label','Show Behavior &LV Overview');
setappdata(gcf,'PlotDLVState',0);
pet_dlv_hdl = getappdata(gcf,'pet_dlv_hdl');
if exist('pet_dlv_hdl','var') & ishandle(pet_dlv_hdl)
try
delete(pet_dlv_hdl);
catch
end
end
case {0}
m_hdl = findobj(gcf,'Tag','DLVMenu');
set(m_hdl,'Label','Hide Behavior &LV Overview');
setappdata(gcf,'PlotDLVState',1);
plot_brain_scores('dlv');
end
return;
%--------------------------------------------------------------------------
%
function ToggleAllerr
allerr_state = getappdata(gcf,'PlotAllerrState');
switch (allerr_state)
case {1}
m_hdl = findobj(gcf,'Tag','AllerrMenu');
set(m_hdl,'Label','Show &Correlation Overview');
setappdata(gcf,'PlotAllerrState',0);
pet_allerr_hdl = getappdata(gcf,'pet_allerr_hdl');
if exist('pet_allerr_hdl','var') & ishandle(pet_allerr_hdl)
try
delete(pet_allerr_hdl);
catch
end
end
case {0}
m_hdl = findobj(gcf,'Tag','AllerrMenu');
set(m_hdl,'Label','Hide &Correlation Overview');
setappdata(gcf,'PlotAllerrState',1);
plot_brain_scores('allerr');
end
return;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?