📄 erp_plot_cond_stim_ui.m
字号:
function erp_plot_cond_stim_ui(action,varargin)
%
% USAGE: erp_plot_cond_stim_ui(action,varargin)
%
% erp_plot_cond_stim_ui('STARTUP',st_data,condition, ...
% axes_margin,plot_dims,cond_idx)
%
% erp_plot_cond_stim_ui('PLOT_STIM', start_cond, start_stim)
% erp_plot_cond_stim_ui('SET_AXES', rows, cols, axes_margin)
% erp_plot_cond_stim_ui('SET_COND_SLIDER')
% erp_plot_cond_stim_ui('SET_STIM_SLIDER')
% erp_plot_cond_stim_ui('UPDATE_DATA',st_data)
% erp_plot_cond_stim_ui('UPDATE_COND_IDX')
% erp_plot_cond_stim_ui('CHANGE_PLOT_DIMS')
% erp_plot_cond_stim_ui('COMBINE_PLOTS')
% erp_plot_cond_stim_ui('NORMALIZE_PLOTS')
% erp_plot_cond_stim_ui('TOGGLE_SHOW_AVERAGE')
% erp_plot_cond_stim_ui('MOVE_COND_SLIDE')
% erp_plot_cond_stim_ui('MOVE_STIM_SLIDE')
%
% Application Data:
% ST_data, ST_condition
% PlotDims, PlotCondIdx, PlotStimCnts
% AxesMargin, AxesHdls, AxesPos
% FirstCondition, FirstStimulus
%
if strcmp(action, 'STARTUP')
init(varargin{1},varargin{2},varargin{3},varargin{4},varargin{5},varargin{6});
elseif strcmp(action, 'PLOT_STIM')
start_cond = varargin{1};
start_stim = varargin{2};
plot_stims(start_cond,start_stim);
elseif strcmp(action, 'SET_AXES')
num_rows = varargin{1};
num_cols = varargin{2};
axes_margin = varargin{3};
set_cond_axes(num_rows,num_cols,axes_margin);
elseif strcmp(action, 'SET_COND_SLIDER')
set_cond_slider;
elseif strcmp(action, 'SET_STIM_SLIDER')
set_stim_slider;
elseif strcmp(action, 'UPDATE_DATA')
st_data = varargin{1};
setappdata(gcf,'ST_data',st_data);
h = findobj(gcf,'Tag','ConditionSlider');
start_cond = get(h,'Max') - round(get(h,'Value')) + 1;
h = findobj(gcf,'Tag','StimulusSlider');
start_stim = round(get(h,'Value'));
plot_stims(start_cond,start_stim);
elseif strcmp(action,'UPDATE_COND_IDX')
setappdata(gcf,'PlotCondIdx',varargin{1});
plot_stims(1,1);
setup_sliders;
elseif strcmp(action,'COMBINE_PLOTS')
combine_state = varargin{1};
combining_plots(combine_state);
elseif strcmp(action,'TOGGLE_SHOW_AVERAGE')
h = findobj(gcf,'Tag','ToggleShowAvgMenu');
switch (getappdata(gcf,'ShowAverage'))
case {0},
setappdata(gcf,'ShowAverage',1);
set(h,'Label','Hide Average Plot');
case {1},
setappdata(gcf,'ShowAverage',0);
set(h,'Label','Show Average Plot');
end;
start_cond = getappdata(gcf,'FirstCondition');
start_stim = getappdata(gcf,'FirstStimulus');
plot_dims = getappdata(gcf,'PlotDims');
axes_margin = getappdata(gcf,'AxesMargin');
set_cond_axes(plot_dims(1),plot_dims(2),axes_margin); % set up axes
set_stim_slider_pos;
plot_stims(start_cond,start_stim);
elseif strcmp(action,'CHANGE_PLOT_DIMS')
h = gcf;
old_dims = getappdata(gcf,'PlotDims');
if isempty(old_dims),
def = {'5','4'};
else
def = {num2str(old_dims(1)), num2str(old_dims(2))};
end;
prompt = {'Number of Rows:','Number of Columns:'};
title = 'Change Plot Dimension';
lines= 1;
row_col = inputdlg(prompt,title,lines,def);
if isempty(row_col), return; end;
new_dims = [str2num(row_col{1}) str2num(row_col{2})];
if (new_dims(2) < 2), new_dims(2) = 2; end;
setappdata(h,'PlotDims',new_dims);
axes_margin = getappdata(gcf,'AxesMargin');
set_cond_axes(new_dims(1),new_dims(2),axes_margin); % set up axes
plot_stims(1,1);
setup_sliders;
elseif strcmp(action, 'MOVE_COND_SLIDE')
h = findobj(gcf,'Tag','ConditionSlider');
start_cond = get(h,'Max') - round(get(h,'Value')) + 1;
if (start_cond ~= getappdata(gcf,'FirstCondition'))
start_stim = getappdata(gcf,'FirstStimulus');
plot_stims(start_cond,start_stim);
end;
elseif strcmp(action, 'MOVE_STIM_SLIDE')
h = findobj(gcf,'Tag','StimulusSlider');
start_stim = round(get(h,'Value'));
if (start_stim ~= getappdata(gcf,'FirstStimulus'))
start_cond = getappdata(gcf,'FirstCondition');
plot_stims(start_cond,start_stim);
end;
elseif strcmp(action, 'RESIZE')
resize_axes;
end;
return;
%--------------------------------------------------------------------------
%
function init(st_data,condition,time_info,axes_margin,plot_dims,cond_idx)
setappdata(gcf,'ST_data',st_data);
setappdata(gcf,'ST_condition',condition);
setappdata(gcf,'time_info',time_info);
setappdata(gcf,'PlotCondIdx',cond_idx);
setappdata(gcf,'PlotDims',plot_dims);
if isempty(getappdata(gcf,'CombinePlots'))
setappdata(gcf,'CombinePlots',0);
end;
if isempty(getappdata(gcf,'ShowAverage'))
setappdata(gcf,'ShowAverage',1);
end;
% set up axes, and the values of 'AxesMargin', 'AxesHlds' and 'AxesPos'
%
setappdata(gcf,'AxesMargin',axes_margin);
set_cond_axes(plot_dims(1),plot_dims(2),axes_margin); % set up axes
stim_cnt_list = [];
for i=1:length(condition),
stim_cnt_list = [stim_cnt_list condition{i}.num_stim];
end;
setappdata(gcf,'PlotStimCnts',stim_cnt_list);
% plot the data and set the values of 'FirstCondition' and 'FirstStimulus'
%
plot_stims(1,1);
setup_sliders; % set up the scroll bars
return; % init
%--------------------------------------------------------------------------
%
function plot_stims(start_cond,start_stim)
% load the information using getappdata
%
ax_hdls = getappdata(gcf,'AxesHdls');
ax_combine_hdls = getappdata(gcf,'AxesCombineHdls');
show_avg = getappdata(gcf,'ShowAverage');
combine_plots = getappdata(gcf,'CombinePlots');
st_data = getappdata(gcf,'ST_data');
st_win_size = size(st_data,2);
condition = getappdata(gcf,'ST_condition');
plot_dims = getappdata(gcf,'PlotDims');
cond_idx = getappdata(gcf,'PlotCondIdx');
time_info = getappdata(gcf,'time_info');
rows = plot_dims(1);
cols = plot_dims(2);
end_cond = start_cond+rows-1;
if (end_cond > length(cond_idx))
end_cond = length(cond_idx);
end;
% suppress average plot if all conditions have at most 1 stim
only_one_stim = 1;
for i=1:length(condition),
if (condition{i}.num_stim > 1),
only_one_stim = 0;
end;
end;
cond_idx = cond_idx(start_cond:end_cond);
for i=1:rows,
for j=1:length(ax_hdls(i,:)),
ax = ax_hdls{i,j};
delete(get(ax,'Children'));
set(ax,'Visible','off');
end;
ax = ax_combine_hdls{i};
delete(get(ax,'Children'));
set(ax,'Visible','off');
end;
end_stim = start_stim + cols - 1;
curr_row = 1;
% x_range = [0:st_win_size-1];
x_range = (time_info.start_timepoint:(time_info.start_timepoint+time_info.timepoint-1))*time_info.digit_interval;
num_conds = length(cond_idx);
for i=1:rows,
if (i > num_conds)
break;
end;
curr_cond = condition{cond_idx(i)};
cdata = st_data(curr_cond.st_row_idx,:);
y_range = [min(cdata(:)), max(cdata(:))];
if (end_stim > curr_cond.num_stim)
end_stim = curr_cond.num_stim;
end;
% plot the data within the current window
%
if (combine_plots), % plot same condition data in a single axes
curr_col = 1;
for j=start_stim:end_stim,
axes(ax_hdls{curr_row,curr_col});
set(ax_hdls{curr_row,curr_col},'Visible','off');
curr_col = curr_col+1;
end;
axes(ax_combine_hdls{curr_row});
set(ax_combine_hdls{curr_row},'Visible','on');
j=[start_stim:end_stim];
plot(x_range,st_data(curr_cond.st_row_idx,:)');
% axis([0 st_win_size-1 y_range(1) y_range(2)]);
axis([time_info.start_timepoint*time_info.digit_interval (time_info.start_timepoint+time_info.timepoint-1)*time_info.digit_interval y_range(1) y_range(2)]);
if (i ~= rows),
set(gca,'XTickLabel',{});
else
% set(gca,'XTick',x_range);
end;
% ylabel(sprintf('Cond. #%d',cond_idx(i)));
ylabel(curr_cond.name);
else
axes(ax_combine_hdls{curr_row});
set(ax_combine_hdls{curr_row},'Visible','off');
curr_col = 1;
for j=start_stim:end_stim,
axes(ax_hdls{curr_row,curr_col});
set(ax_hdls{curr_row,curr_col},'Visible','on');
st_row = curr_cond.st_row_idx(j);
if (start_stim <= curr_cond.num_stim)
plot(x_range,st_data(st_row,:));
% axis([0 st_win_size-1 y_range(1) y_range(2)]);
axis([time_info.start_timepoint*time_info.digit_interval (time_info.start_timepoint+time_info.timepoint-1)*time_info.digit_interval y_range(1) y_range(2)]);
% set(gca,'XTick',[1:2:x_range(end)]);
end;
if (curr_col == 1),
% ylabel(sprintf('Cond. #%d',cond_idx(i)));
ylabel(curr_cond.name);
else
set(gca,'YTickLabel',{});
end;
if (i == 1),
if strcmp(get(gcf,'user'),'datamatcorrs')
set(gca,'Title', text('String',sprintf('Behav. #%d',j),'Interpreter','none'));
else
set(gca,'Title', text('String',sprintf('Avg. Subj. #%d',j),'Interpreter','none'));
end
get(gca,'xlabel');
end;
if (i ~= length(cond_idx)), set(gca,'XTickLabel',{}); end;
curr_col = curr_col+1;
end;
end;
% plot the average data for the condition in the last column
%
if (show_avg == 1),
avg_col = cols + 1;
axes(ax_hdls{curr_row,avg_col});
if (only_one_stim == 0)
set(ax_hdls{curr_row,avg_col},'Visible','on');
mean_cdata = mean(cdata,1);
plot(x_range,mean_cdata,'r');
% axis([0 st_win_size-1 min(mean_cdata) max(mean_cdata)]);
axis([time_info.start_timepoint*time_info.digit_interval (time_info.start_timepoint+time_info.timepoint-1)*time_info.digit_interval min(mean_cdata) max(mean_cdata)]);
% set(gca,'YAxisLocation','right','XTick',[1:2:x_range(end)]);
set(gca,'YAxisLocation','right');
if (i == 1)
set(gca,'Title', text('String','Average','Interpreter','none'));
get(gca,'xlabel');
end
if (i ~= length(cond_idx)), set(gca,'XTickLabel',{}); end;
else
set(ax_hdls{curr_row,avg_col},'Visible','off');
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -