📄 pet_plot_cond_stim_ui.m
字号:
function pet_plot_cond_stim_ui(action,varargin)
%
% USAGE: pet_plot_cond_stim_ui(action,varargin)
%
% pet_plot_cond_stim_ui('STARTUP',st_data,condition, ...
% axes_margin,plot_dims,cond_idx)
%
% pet_plot_cond_stim_ui('PLOT_STIM', start_cond, start_stim)
% pet_plot_cond_stim_ui('SET_AXES', rows, cols, axes_margin)
% pet_plot_cond_stim_ui('SET_COND_SLIDER')
% pet_plot_cond_stim_ui('SET_STIM_SLIDER')
% pet_plot_cond_stim_ui('UPDATE_DATA',st_data)
% pet_plot_cond_stim_ui('UPDATE_COND_IDX')
% pet_plot_cond_stim_ui('CHANGE_PLOT_DIMS')
% pet_plot_cond_stim_ui('COMBINE_PLOTS')
% pet_plot_cond_stim_ui('NORMALIZE_PLOTS')
% pet_plot_cond_stim_ui('TOGGLE_SHOW_AVERAGE')
% pet_plot_cond_stim_ui('MOVE_COND_SLIDE')
% pet_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});
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 = {'1','1'};
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, 'TOGGLELEGEND')
ToggleLegend;
elseif strcmp(action, 'fig_bt_dn')
fig_bt_dn;
elseif strcmp(action, 'select_subj')
select_subj;
end;
return;
%--------------------------------------------------------------------------
%
function init(st_data,condition,axes_margin,plot_dims,cond_idx)
setappdata(gcf,'ST_data',st_data);
setappdata(gcf,'ST_condition',condition);
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',0);
% 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)
try
txtbox_hdl = getappdata(gcf,'txtbox_hdl');
delete(txtbox_hdl); % clear rri_txtbox
catch
end
% load the information using getappdata
%
ax_hdls = getappdata(gcf,'AxesHdls');
st_data = getappdata(gcf,'ST_data');
condition = getappdata(gcf,'ST_condition');
plot_dims = getappdata(gcf,'PlotDims');
cond_idx1 = getappdata(gcf,'PlotCondIdx');
curr_fig = gcf;
rows = plot_dims(1);
cols = plot_dims(2);
end_cond = start_cond+rows-1;
if (end_cond > length(cond_idx1))
end_cond = length(cond_idx1);
end;
cond_idx = cond_idx1(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;
end;
end_stim = start_stim + cols - 1;
curr_row = 1;
cond_name = condition.cond_name;
subj_name = condition.subj_name;
plotmarkercolour=[
'bo';'rd';'g<';'m>';'bs';'rv';'g^';'mp';'bh';'rx';'g+';'m*';
'ro';'gd';'m<';'b>';'rs';'gv';'m^';'bp';'rh';'gx';'m+';'b*';
'go';'md';'b<';'r>';'gs';'mv';'b^';'rp';'gh';'mx';'b+';'r*';
'mo';'bd';'r<';'g>';'ms';'bv';'r^';'gp';'mh';'bx';'r+';'g*'];
if length(subj_name)>length(plotmarkercolour) % need more color
tmp = [];
for i=1:ceil( length(subj_name)/length(plotmarkercolour) )
tmp = [tmp; plotmarkercolour];
end
plotmarkercolour = tmp;
end
linc_wave = st_data.linc_wave;
brain_wave = st_data.brain_wave;
behav_wave = st_data.behav_wave;
behavname = st_data.behavname;
strong_r = st_data.strong_r;
brainscores = getappdata(gcf, 'brainscores');
behavdata = getappdata(gcf, 'behavdata');
% min_x = min(behavdata(:)); max_x = max(behavdata(:));
min_y = min(brainscores(:)); max_y = max(brainscores(:));
% margin_x = abs((max_x - min_x) / 20);
margin_y = abs((max_y - min_y) / 20);
numbehav = size(behav_wave, 2);
num_conds = size(behav_wave, 3);
brain_state = getappdata(gcf,'PlotBrainState');
if(brain_state) % plot brain scores
err_ax = getappdata(gcf,'ErrHdls');
set(err_ax,'visible','off');
for i = 1:rows
if (i > num_conds)
break;
end;
if (end_stim > numbehav)
end_stim = numbehav;
end;
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');
set(ax_hdls{curr_row,curr_col}, ...
'buttondown','pet_plot_cond_stim_ui(''fig_bt_dn'');');
if (start_stim <= numbehav)
cla;grid off;box off;hold on;
plot(behav_wave(:,j,cond_idx(i)), linc_wave(:,j,cond_idx(i)));
for n=1:length(subj_name)
score_hdl(i,j,n) = plot(behav_wave(n,j,cond_idx(i)), ...
brain_wave(n,1,cond_idx(i)),plotmarkercolour(n,:), ...
'MarkerSize',10, 'userdata', n, 'buttondown', ...
'pet_plot_cond_stim_ui(''select_subj'');');
end
per_behav = behav_wave(:,j,:);
min_x = min(per_behav(:)); max_x = max(per_behav(:));
margin_x = abs((max_x - min_x) / 20);
axis([min_x-margin_x,max_x+margin_x, ...
min_y-margin_y,max_y+margin_y]);
% axis([0 st_win_size-1 y_range(1) y_range(2)]);
% set(gca,'XTick',[1:2:x_range(end)]);
end; % enf if
if (curr_col == 1),
% ylabel(sprintf('Cond. #%d',cond_idx(i)));
ylabel(cond_name{cond_idx(i)});
else
% set(gca,'YTickLabel',{});
end;
if (i == length(cond_idx)),
% xlabel(sprintf('Behav. #%d',j));
xlabel(behavname{j});
else
% set(gca,'XTickLabel',{});
end;
if (curr_col == 1) & (i == 1)
% [l_hdl o_hdl] = legend(subj_name);
% legend_txt(o_hdl);
end
LV = num2str(find(getappdata(gcf, 'CurrLVState')));
title(['LV=',LV,', r=',num2str(strong_r(1,j,cond_idx(i)),2)]);
get(gca,'xlabel');
if(0)
txtbox(i,j)=rri_txtbox(gca, 'LV', LV, ...
'r', num2str(strong_r(1,j,cond_idx(i)),2));
pos_a = get(gca,'position');
pos = get(txtbox(i,j),'position');
pos(1) = pos_a(1) + .005;
pos(2) = pos_a(2) + .005;
set(txtbox(i,j),'position',pos);
set(txtbox(i,j),'tag','tmp');
end
curr_col = curr_col+1;
end; % end for j
curr_row = curr_row+1;
end % enf for i
setappdata(gcf, 'score_hdl', score_hdl);
for i = 1:rows
if (i > num_conds)
break;
end;
if (end_stim > numbehav)
end_stim = numbehav;
end;
if(0)
for j=start_stim:end_stim,
set(txtbox(i,j),'tag','rri_txtbox');
end
end
end
% 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(subj_name, 0);
legend_txt(o_hdl);
set(l_hdl,'color',[0.9 1 0.9]);
setappdata(gcf,'LegendHdl',[{l_hdl} {o_hdl}]);
% setappdata(gcf,'txtbox',txtbox);
legend_state = get(findobj(gcf,'Tag','LegendMenu'),'Userdata');
if (legend_state == 1),
DisplayLegend('on');
else
DisplayLegend('off');
end;
setappdata(gcf,'FirstCondition',start_cond);
setappdata(gcf,'FirstStimulus',start_stim);
else % plot errorbar
mask = [];
for i=1:numbehav
for j=1:num_conds
mask = [mask (j-1)*numbehav+i];
end
end
orig_corr = st_data.orig_corr;
if isempty(st_data.ulcorr)
llcorr = st_data.llcorr - st_data.orig_corr;
ulcorr = [];
else
llcorr = st_data.llcorr - st_data.orig_corr;
ulcorr = st_data.ulcorr - st_data.orig_corr;
end
ax_hdls = getappdata(gcf,'AxesHdls');
[r c] = size(ax_hdls);
for i = 1:r
for j = 1:c
set(ax_hdls{i,j},'Visible','off');
end
end
txtbox = getappdata(gcf,'txtbox');
[r c] = size(txtbox);
for i = 1:r
for j = 1:c
try
delete(txtbox(i,j));
catch
end;
end
end
old_legend = getappdata(gcf,'LegendHdl');
if ~isempty(old_legend),
try
delete(old_legend{1});
catch
end;
end;
err_ax = getappdata(gcf,'ErrHdls');
set(err_ax,'visible','on');
cla;grid on;box on;hold on;
% h1 = bar(orig_corr(mask));
% set(h1, 'facecolor', 'none');
load('rri_color_code');
for i=1:numbehav
for j=1:num_conds
k = (i-1)*num_conds + j;
bar_hdl = bar(k, orig_corr(mask(k)));
set(bar_hdl,'facecolor',color_code(j,:));
end
end
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}]);
legend_state = get(findobj(gcf,'Tag','LegendMenu'),'Userdata');
if (legend_state == 1),
DisplayLegend('on');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -