📄 fmri_plot_hrf.m
字号:
% Show Hemodynamic Response Function for PLS MRI session
%
% Usage:
% 1. fmri_plot_hrf(session_file); % file name string
% 2. or: fmri_plot_hrf(session_info); % session_info struct
% 3. or: fmri_plot_hrf(condition, evt_onsets);
% where: condition = session_info.condition;
% evt_onsets = session_info.run(r).evt_onsets;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function h01 = fmri_plot_hrf(varargin)
if nargin == 0 % just for test usage
load test_fmrisession;
condition = session_info.condition;
evt_onsets = session_info.run(1).evt_onsets;
h01 = init(condition, evt_onsets);
return;
elseif nargin == 2 & iscell(varargin{1})
h01 = init(varargin{1},varargin{2});
return;
elseif nargin == 1 & isstruct(varargin{1})
session_info = varargin{1};
condition = session_info.condition;
run = session_info.run;
for r = 1:length(run)
evt_onsets = session_info.run(r).evt_onsets;
h01 = fmri_plot_hrf(condition, evt_onsets);
set(gcf, 'name', ['Run #', num2str(r)]);
end
return;
elseif nargin == 1 & ischar(varargin{1})
load(varargin{1});
h01 = fmri_plot_hrf(session_info);
return;
end
% clear the message line,
%
h = findobj(gcf,'Tag','MessageLine');
set(h,'String','');
switch varargin{1}{1}
case 'MOVE_COND_SLIDE'
h = findobj(gcf,'Tag','ConditionSlider');
start_cond = get(h,'Max') - round(get(h,'Value')) + 1;
plot_hrf(start_cond);
case {'TR', 'win_size'}
h = findobj(gcf, 'Tag', 'TR');
TR = str2num(get(h, 'string'));
if TR < 1
TR = getappdata(gcf, 'TR');
set(h, 'string', num2str(TR));
msg = 'Please select an integer between 1 and 5';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
h = findobj(gcf, 'Tag', 'win_size');
win_size = str2num(get(h, 'string'));
if win_size < 1
win_size = getappdata(gcf, 'win_size');
set(h, 'string', num2str(win_size));
msg = 'Please select an integer between 1 and 5';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
setappdata(gcf,'TR',TR);
setappdata(gcf,'win_size',win_size);
evt_onsets = getappdata(gcf,'evt_onsets');
condition = getappdata(gcf,'condition');
[x1 y1 x2 y2 y22] = fmri_hrf_data(evt_onsets, condition, TR, win_size);
setappdata(gcf,'x1',x1);
setappdata(gcf,'y1',y1);
setappdata(gcf,'x2',x2);
setappdata(gcf,'y2',y2);
setappdata(gcf,'y22',y22);
start_cond = getappdata(gcf,'start_cond');
plot_hrf(start_cond);
case 'NumRows'
h = findobj(gcf, 'Tag', 'NumRows');
disp_num_conditions = str2num(get(h, 'string'));
if disp_num_conditions > 5 | disp_num_conditions < 1
plot_dims = getappdata(gcf, 'PlotDims');
set(h, 'string', num2str(plot_dims(1)));
msg = 'Please select an integer between 1 and 5';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
plot_dims = [disp_num_conditions, 1];
setappdata(gcf, 'PlotDims', plot_dims);
axes_margin = getappdata(gcf,'AxesMargin');
set_cond_axes(plot_dims(1),plot_dims(2),axes_margin); % set up axes
plot_hrf(1);
setup_sliders;
case 'zoom'
zoom_on_state = get(gcbo,'Userdata');
if (zoom_on_state == 1) % zoom on
zoom on;
set(gcbo,'Userdata',0,'Label','&Zoom off');
set(gcf,'pointer','crosshair');
else % zoom off
zoom off;
set(gcbo,'Userdata',1,'Label','&Zoom on');
set(gcf,'pointer','arrow');
end
case 'TOGGLE_SHOW_AVERAGE'
h = findobj(gcf,'Tag','ToggleShowAvgMenu');
switch (getappdata(gcf,'ShowAverage'))
case {0},
setappdata(gcf,'ShowAverage',1);
set(h,'Label','Hide average');
case {1},
setappdata(gcf,'ShowAverage',0);
set(h,'Label','Plot average');
end;
start_cond = getappdata(gcf,'start_cond');
h = findobj(gcf, 'Tag', 'NumRows');
plot_dims = [str2num(get(h, 'string')), 1];
setappdata(gcf, 'PlotDims', plot_dims);
axes_margin = getappdata(gcf,'AxesMargin');
set_cond_axes(plot_dims(1),plot_dims(2),axes_margin); % set up axes
plot_hrf(start_cond);
case 'TOGGLE_SHOW_COMBINED'
h = findobj(gcf,'Tag','ToggleShowCombinedMenu');
switch (getappdata(gcf,'CombinedPlots'))
case {0},
setappdata(gcf,'CombinedPlots',1);
set(h,'Label','Plot individual condition');
case {1},
setappdata(gcf,'CombinedPlots',0);
set(h,'Label','Plot combined condition');
end;
start_cond = getappdata(gcf,'start_cond');
plot_hrf(start_cond);
case 'delete_fig'
delete_fig;
end
return; % fmri_plot_hrf
%--------------------------------------------------------------------------
%
function hh = init(condition, evt_onsets)
for i = 1:length(evt_onsets)
evt_onsets{i} = evt_onsets{i}(:);
end
num_conditions = length(condition);
if num_conditions > 5
disp_num_conditions = 5;
else
disp_num_conditions = num_conditions;
end
save_setting_status = 'on';
fmri_plot_hrf_pos = [];
try
load('pls_profile');
catch
end
if ~isempty(fmri_plot_hrf_pos) & strcmp(save_setting_status,'on')
pos = fmri_plot_hrf_pos;
else
w = 0.9;
h = 0.7;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
end
hh = figure('Units','normal', ...
'Name','Hemodynamic Response Function Plot', ...
'NumberTitle','off', ...
'Color', [0.8 0.8 0.8], ...
'DoubleBuffer','on', ...
'Menubar', 'none', ...
'DeleteFcn', 'fmri_plot_hrf({''delete_fig''});', ...
'Position',pos, ...
'Tag','PlotHRFFig');
x = 0.05;
y = 0.08;
w = 0.11;
h = 0.05;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'text', ...
'Position', pos, ...
'background', [.8 .8 .8], ...
'String', 'Window Size:');
x = x + w;
w = 0.04;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'edit', ...
'Position', pos, ...
'background', [1 1 1], ...
'String', '8', ...
'Callback','fmri_plot_hrf({''win_size''});', ...
'Tag', 'win_size');
x = x + w;
w = 0.1;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'text', ...
'Position', pos, ...
'background', [.8 .8 .8], ...
'String', '(TimePoints)');
x = x + w + 0.01;
w = 0.05;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'text', ...
'Position', pos, ...
'background', [.8 .8 .8], ...
'String', 'TR:');
x = x + w;
w = 0.04;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'edit', ...
'Position', pos, ...
'background', [1 1 1], ...
'String', '2', ...
'Callback','fmri_plot_hrf({''TR''});', ...
'Tag', 'TR');
x = x + w;
w = 0.08;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'text', ...
'Position', pos, ...
'background', [.8 .8 .8], ...
'String', '(Seconds)');
x = x + w + 0.01;
w = 0.25;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'text', ...
'Position', pos, ...
'background', [.8 .8 .8], ...
'String', 'Number of conditions per display:');
x = x + w;
w = 0.04;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ...
'Units','normal', ...
'FontSize', 12, ...
'Style', 'edit', ...
'Position', pos, ...
'background', [1 1 1], ...
'String', num2str(disp_num_conditions), ...
'Callback','fmri_plot_hrf({''NumRows''});', ...
'Tag', 'NumRows');
x = 0.01;
y = 0;
w = 1;
h = 0.05;
pos = [x y w h];
h1 = uicontrol('Parent',hh, ... % Message Line
'Style','text', ...
'Units','normal', ...
'FontSize', 12, ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0.8 0.0 0.0], ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Tag','MessageLine');
% file menu
%
rri_file_menu(hh);
% zoom
%
h1 = uimenu('parent',hh, ...
'userdata', 1, ...
'callback','fmri_plot_hrf({''zoom''});', ...
'label','&Zoom on');
% show/hide avg
%
h1 = uimenu('Parent',hh, ...
'Label','Hide average', ...
'Tag','ToggleShowAvgMenu', ...
'Callback','fmri_plot_hrf({''TOGGLE_SHOW_AVERAGE''});');
% show/hide combined
%
h1 = uimenu('Parent',hh, ...
'Label','Plot combined condition', ...
'Tag','ToggleShowCombinedMenu', ...
'Callback','fmri_plot_hrf({''TOGGLE_SHOW_COMBINED''});');
% Help submenu
%
Hm_topHelp = uimenu('Parent',hh, ...
'Label', '&Help', ...
'Tag', 'Help');
Hm_how = uimenu('Parent',Hm_topHelp, ...
'Label', '&How to use this window?', ...
'Callback','rri_helpfile_ui(''fmri_plot_hrf_hlp.txt'',''How to use it'');', ...
'visible', 'off', ...
'Tag', 'How');
Hm_new = uimenu('Parent',Hm_topHelp, ...
'Label', '&What''s new', ...
'Callback','rri_helpfile_ui(''whatsnew.txt'',''What''''s new'');', ...
'Tag', 'New');
Hm_about = uimenu('Parent',Hm_topHelp, ...
'Label', '&About this program', ...
'Tag', 'About', ...
'CallBack', 'plsgui_version');
setappdata(gcf,'evt_onsets', evt_onsets);
setappdata(gcf,'condition', condition);
setappdata(gcf,'ShowAverage',1);
setappdata(gcf,'CombinedPlots',0);
TR = 2; % init. value for user guessing
setappdata(gcf,'TR',TR);
win_size = 8; % init. value for user guessing
setappdata(gcf,'win_size',win_size);
cond_idx = [1:num_conditions];
setappdata(gcf,'PlotCondIdx',cond_idx);
plot_dims = [disp_num_conditions 1];
setappdata(gcf,'PlotDims',plot_dims);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -