📄 struct_plot_rf.m
字号:
st_data = getappdata(gcf,'STDatamat');
data = st_data(:,coord_idx);
[filename, pathname] = ...
uiputfile('*_STRUCT_rf_plot.mat','Save the Response Functions');
if ischar(filename) & isempty(findstr(lower(filename),'_struct_rf_plot'))
[tmp filename] = fileparts(filename);
filename = [filename, '_STRUCT_rf_plot.mat'];
end
if isequal(filename,0)
return;
end;
rf_plot_file = fullfile(pathname,filename);
xyz_str = 'xyz';
sa = getappdata(gcf, 'sa');
if ~isempty(sa) & sa == 1
yzx = xyz;
xyz_str = 'yzx';
elseif ~isempty(sa) & sa == 0
xzy = xyz;
xyz_str = 'xzy';
end
try
save (rf_plot_file, 'selected_files', 'data', xyz_str );
catch
msg = sprintf('Cannot save the response function data to %s',rf_plot_file);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
return; % save_response_fn
%--------------------------------------------------------------------------
%
function save_response_fn2()
st_coords = getappdata(gcf,'STCoords');
org_coords = getappdata(gcf,'org_coords');
xyz = getappdata(gcf,'XYZ');
h = findobj(gcf,'Tag','STDatamatPopup');
selected_idx = get(h,'Value');
% extract the currect ploting data
%
cur_coord = getappdata(gcf,'Coord');
if isempty(cur_coord)
msg = 'ERROR: No point has been seleted to plot.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
coord_idx = find(st_coords == cur_coord);
if isempty(coord_idx)
msg = 'ERROR: The selected point is outside the brain region.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
coord_idx = find(org_coords == cur_coord);
% extract the data of the selected voxel
%
st_data = getappdata(gcf,'STDatamat');
data = double(st_data(:,coord_idx));
pattern = ['*_struct_grp', num2str(selected_idx), '_behavdata.txt'];
pattern_suffix = ['_struct_grp', num2str(selected_idx), '_behavdata.txt'];
[filename, pathname] = uiputfile(pattern,'Save Behav Data');
if ischar(filename) & isempty(findstr(lower(filename), lower(pattern_suffix)))
[tmp filename] = fileparts(filename);
filename = [filename, pattern_suffix];
end
if isequal(filename,0)
return;
end;
rf_plot_file = fullfile(pathname,filename);
try
save (rf_plot_file, '-ascii', 'data');
catch
msg = sprintf('Cannot save the response function data to %s',rf_plot_file);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
return; % save_response_fn2
%--------------------------------------------------------------------------
%
function save_response_behav()
st_coords = getappdata(gcf,'STCoords');
org_coords = getappdata(gcf,'org_coords');
xyz = getappdata(gcf,'XYZ');
% extract the currect ploting data
%
cur_coord = getappdata(gcf,'Coord');
if isempty(cur_coord)
msg = 'ERROR: No point has been seleted to plot.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
st_data = getappdata(gcf,'STDatamat');
coord_idx = find(st_coords == cur_coord);
if isempty(coord_idx)
msg = 'ERROR: The selected point is outside the brain region.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
coord_idx = find(org_coords == cur_coord);
st_data = getappdata(gcf,'datamatcorrs');
data = st_data(:,coord_idx);
[filename, pathname] = ...
uiputfile('*_STRUCT_datamatcorr_plot.mat','Save the Response Functions');
if ischar(filename) & isempty(findstr(lower(filename),'_struct_datamatcorr_plot'))
[tmp filename] = fileparts(filename);
filename = [filename, '_STRUCT_datamatcorr_plot.mat'];
end
if isequal(filename,0)
return;
end;
rf_plot_file = fullfile(pathname,filename);
try
save (rf_plot_file, 'data', 'xyz' );
catch
msg = sprintf('Cannot save the response function data to %s',rf_plot_file);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
return; % save_response_behav
%--------------------------------------------------------------------------
%
function set_cond_axes(num_rows,num_cols,axes_margin)
%
% Define the axes for the response functions of different conditions
%
% axes_margin: [left right bottom top], which specified in terms of
% normal unit respect to the figure;
%
show_avg = getappdata(gcf,'ShowAverage');
if ~isempty(show_avg) & (show_avg == 1),
num_cols = num_cols + 1;
end;
% clear up the old handles
%
old_hdls = getappdata(gcf,'AxesHdls');
if ~isempty(old_hdls)
for i=1:length(old_hdls(:))
if ishandle(old_hdls{i}), delete(old_hdls{i}); end
end;
end;
old_hdls = getappdata(gcf,'AxesCombineHdls');
if ~isempty(old_hdls)
for i=1:length(old_hdls(:))
if ishandle(old_hdls{i}), delete(old_hdls{i}); end
end;
end;
f_pos = get(gcf,'Position');
axes_boundary(1) = axes_margin(1);
axes_boundary(2) = 1 - axes_margin(2);
axes_boundary(3) = axes_margin(3);
axes_boundary(4) = 1 - axes_margin(4);
% plot data in each axis
%
ax_hdls = cell(num_rows,num_cols);
ax_pos = cell(num_rows,num_cols);
ax_combine_hdls = cell(num_rows,1);
ax_combine_pos = cell(num_rows,1);
plot_width = (axes_boundary(2) - axes_boundary(1)) / num_cols;
plot_height = (axes_boundary(4) - axes_boundary(3)) / num_rows;
axes_min_x = axes_boundary(1);
axes_min_y = axes_boundary(3);
for row=1:num_rows,
axes_y = axes_min_y + plot_height*(num_rows-row);
% for separate plots within each condition
%
for col=1:num_cols,
% determine the position of the figure
%
axes_x = axes_min_x + plot_width*(col-1);
if (col == num_cols & ~isempty(show_avg) & show_avg == 1)
axes_pos = [axes_x+0.02 axes_y plot_width-0.01 plot_height-0.03];
else
axes_pos = [axes_x axes_y plot_width-0.01 plot_height-0.03];
end;
ax = axes('units','normal','Position',axes_pos);
set(ax,'units',get(gcf,'defaultaxesunits'));
set(ax,'visible','off');
ax_hdls{row,col} = ax;
ax_pos{row,col} = axes_pos;
end,
% for combine plots within each condition
%
combine_axes_x = axes_min_x;
combine_axes_y = axes_y;
if (~isempty(show_avg) & show_avg == 1)
combine_axes_w = plot_width*(num_cols-1)-0.01;
else
combine_axes_w = plot_width*num_cols-0.01;
end;
combine_axes_h = plot_height-0.03;
axes_pos = [combine_axes_x combine_axes_y combine_axes_w combine_axes_h];
ax = axes('units','normal','Position',axes_pos, ...
'box', 'on', ...
'tickdir', 'out', ...
'ticklength', [0.005 0.005]);
set(ax,'units',get(gcf,'defaultaxesunits'));
% set(ax,'visible','off');
ax_combine_hdls{row} = ax;
ax_combine_pos{row} = axes_pos;
end;
setappdata(gcf,'AxesHdls',ax_hdls);
setappdata(gcf,'AxesPos',ax_pos);
setappdata(gcf,'AxesCombineHdls',ax_combine_hdls);
setappdata(gcf,'AxesCombinePos',ax_combine_pos);
return; % set_cond_axes
%--------------------------------------------------------------------------
%
function plot_datamatcorrs
axes_margin = [.37 .05 .15 .1];
% set up axes, and the values of 'AxesMargin', 'AxesHlds' and 'AxesPos'
%
setappdata(gcf,'AxesMargin',axes_margin);
set_cond_axes(1,1,axes_margin); % set up axes
st_coords = getappdata(gcf,'STCoords');
st_files = getappdata(gcf,'STFiles');
h = findobj(gcf,'Tag','STDatamatPopup');
popup_string = get(h,'String');
selected_idx = get(h,'Value');
selected_data = popup_string{selected_idx};
% load the datamat if not loaded yet
%
last_datamat = getappdata(gcf,'PlottedDatamat');
if strcmp(last_datamat,selected_data) == 0
set(findobj(gcf,'Tag','MessageLine'),'String','Loading data ... ');
[st_datamat,org_coords,num_subj,subj_name,cond_name,behavname]= ...
load_plotted_datamat;
result_file = ...
get(findobj(getappdata(gcf,'CallBackFig'),'tag','ResultFile'),'UserData');
warning off;
try
load(result_file,'behavname');
catch
end
warning on;
cond_selection = getappdata(gcf,'cond_selection');
if isempty(cond_selection)
cond_selection = ones(1,length(cond_name));
else
cond_name = cond_name(find(cond_selection));
end
% selected_subjects = ones(num_subj,1);
% bmask = selected_subjects * cond_selection;
% bmask = find(bmask(:));
% st_datamat = st_datamat(bmask,:);
setappdata(gcf,'PlottedDatamat',selected_data);
% setappdata(gcf,'STDatamat',st_datamat);
setappdata(gcf,'org_coords',org_coords);
setappdata(gcf,'num_subj',num_subj);
setappdata(gcf,'subj_name',subj_name);
setappdata(gcf,'cond_name',cond_name);
setappdata(gcf,'behavname',behavname);
datamatcorrs = getappdata(gcf, 'datamatcorrs_lst');
setappdata(gcf,'datamatcorrs', datamatcorrs{selected_idx});
set(findobj(gcf,'Tag','MessageLine'),'String','');
else
org_coords = getappdata(gcf,'org_coords');
end;
% extract the currect ploting data
%
cur_coord = getappdata(gcf,'Coord');
if isempty(cur_coord)
msg = 'ERROR: No point has been seleted to plot.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
set(gca,'visible','off');
return;
end;
coord_idx = find(st_coords == cur_coord);
if isempty(coord_idx)
msg = 'ERROR: The selected point is outside the brain region.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
set(gca,'visible','off');
return;
end;
% coord_idx = find(org_coords == cur_coord);
selected_condition = getappdata(gcf,'SelectedCondition');
num_cond = sum(selected_condition);
st_data = getappdata(gcf,'datamatcorrs');
num_behav = size(st_data,1)/num_cond;
% generate the plots
%
cond_idx = find(selected_condition == 1);
setappdata(gcf,'ST_data',st_data);
setappdata(gcf,'PlotCondIdx',cond_idx);
if isempty(getappdata(gcf,'CombinePlots'))
setappdata(gcf,'CombinePlots',0);
end;
if isempty(getappdata(gcf,'ShowAverage'))
setappdata(gcf,'ShowAverage',0);
end;
% the following code is to get an intensity array for the voxel and plot it
% find out the coord_idx
%
% coord = getappdata(gcf,'Coord');
% org_coords = getappdata(gcf,'org_coords');
% coord_idx = find(org_coords == coord);
if 0
behav_name = {};
for i=1:num_behav
behav_name = [behav_name, {['Behav. #', num2str(i)]}];
end
behav_name = [behav_name, {'mean'}];
end
% behavname = [behavname, {'mean'}];
for k = cond_idx % cond
for n = 1:num_behav % behav
j = n+(k-1)*num_behav; % row number in datamat
% intensity(k,n) = st_data(j, coord_idx);
% intensity_hdl(k,n) = 0; % initialization
intensity(j) = st_data(j, coord_idx);
end
% intensity_avg_hdl(k) = 0;
end
% intensity_avg = mean(intensity,2);
if(0)
color_code =[ 'bo';'rx';'g+';'m*';'bs';'rd';'g^';'m<';'bp';'r>'; ...
'gh';'mv';'ro';'gx';'m+';'b*';'rs';'gd';'m^';'b<'];
% need more color
%
if num_behav+1 > size(color_code,1)
tmp = [];
for i=1:ceil((num_behav+1)/size(color_code,1))
tmp = [tmp; color_code];
end
color_code = tmp;
end
end
mask = [];
for i=1:num_behav
for j=1:num_cond
mask = [mask (j-1)*num_behav+i];
end
end
cla;grid on;box on;hold on;
load('rri_color_code');
for i=1:num_behav
for j=1:num_cond
k = (i-1)*num_cond + j;
bar_hdl = bar(k, intensity(mask(k)));
set(bar_hdl,'facecolor',color_code(j,:));
end
end
if(0)
for k = cond_idx
for n = 1:num_behav
intensity_hdl(k,n) = plot(k,intensity(k,n), ...
color_code(n,:));
end
intensity_avg_hdl(k) = bar(k,intensity_avg(k));
set(intensity_avg_hdl(k),'facecolor','none')
% set(intensity_avg_hdl(k), 'linewidth', 2);
end
axis([0 length(cond_idx)+1 -1-.05 1+.05]);
% set(gca, 'xtick', cond_idx);
left = repmat('(',[length(cond_idx),1]);
mid = num2str(cond_idx');
right = repmat(')',[length(cond_idx),1]);
set(gca, 'xticklabel', [left mid right]);
xlabel('Conditions');
end
min_x = 0.5; max_x = num_cond * num_behav + 0.5;
min_y =-1; max_y = 1;
margin_x = abs((max_x - min_x) / 20);
margin_y = abs((max_y - min_y) / 20);
axis([min_x-margin_x,max_x+margin_x,min_y-margin_y,max_y+margin_y]);
set(gca,'xtick',[1:num_cond:num_cond*num_behav]);
behavname = getappdata(gcf,'behavname');
cond_name = getappdata(gcf,'cond_name');
set(gca,'xticklabel',behavname);
ylabel('Correlation');
xyz = getappdata(gcf,'XYZ');
title(['Datamat correlations at voxel: [',num2str(xyz),']']);
hold off;
l_hdl = [];
if ~isempty(cond_name),
% remove the old legend to avoid the bug in the MATLAB5
old_legend = getappdata(gcf,'LegendHdl');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
% create a new legend, and save the handles
[l_hdl, o_hdl] = legend(cond_name, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(gcf,'LegendHdl',[{l_hdl} {o_hdl}]);
else
setappdata(gcf,'LegendHdl',[]);
end;
if(0)
if ~isempty(behavname),
intensity_legend = [intensity_hdl(1,:), intensity_avg_hdl(1)];
% remove the old legend to avoid the bug in the MATLAB5
old_legend = getappdata(gcf,'LegendHdl');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
% create a new legend, and save the handles
[l_hdl, o_hdl] = legend(intensity_legend, behavname, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(gcf,'LegendHdl',[{l_hdl} {o_hdl}]);
else
setappdata(gcf,'LegendHdl',[]);
end;
end
set(findobj(gcf,'Tag','DataMenuBehav'),'visible','on');
return; % plot_datamatcorrs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -