⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmri_plot_hrf.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 2 页
字号:
   [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);

   % set up axes, and the values of 'AxesMargin', 'AxesHlds' and 'AxesPos'
   %
   axes_margin = [.1 .1 .2 .03];
   setappdata(gcf,'AxesMargin',axes_margin);

   set_cond_axes(plot_dims(1),plot_dims(2),axes_margin);	% set up axes

   % plot the data and set the values of 'start_cond'
   %
   plot_hrf(1);					

   setup_sliders; 		% set up the scroll bars 

   return;						% init


%--------------------------------------------------------------------------
%
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 (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_width2 = 0.2;

  if (show_avg == 1),
     plot_width  = (axes_boundary(2) - axes_boundary(1)) - plot_width2 - 0.01;
  else
     plot_width  = (axes_boundary(2) - axes_boundary(1));
  end

  plot_height = (axes_boundary(4) - axes_boundary(3)) / num_rows - 0.06;
  axes_min_x = axes_boundary(1);
  axes_min_y = axes_boundary(3);

  for row=1:num_rows, 

    axes_y = axes_min_y + (plot_height + 0.06) * (num_rows - row);

    %  determine the position of the figure
    %
    axes_x = axes_min_x;
    axes_pos = [axes_x, axes_y, plot_width, plot_height];
    
    ax = axes('units','normal','Position',axes_pos);
    set(ax,'units',get(gcf,'defaultaxesunits'));
    set(ax,'visible','off');
   
    ax_hdls{row,1} = ax;  
    ax_pos{row,1} = axes_pos;

    if (show_avg == 1),
       axes_x = axes_min_x + plot_width + 0.01;
       axes_pos = [axes_x, axes_y, plot_width2, plot_height];

       ax = axes('units','normal','Position',axes_pos);
       set(ax,'units',get(gcf,'defaultaxesunits'));
       set(ax,'visible','off');

       ax_hdls{row,2} = ax;  
       ax_pos{row,2} = axes_pos;
    end

    % for combine plots within each condition 
    %
    combine_axes_x = axes_min_x;
    combine_axes_y = axes_y;
    combine_axes_w = plot_width;
    combine_axes_h = plot_height;

    axes_pos = [combine_axes_x combine_axes_y combine_axes_w combine_axes_h];
    ax = axes('units','normal','Position',axes_pos);

    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 setup_sliders()
%
  %  remove the old sliders first
  %
  h = findobj(gcf,'Tag','ConditionSlider'); 
  if ~isempty(h), delete(h); end;

  %  set up sliders when needed
  %
  plot_dims = getappdata(gcf,'PlotDims');
  cond_idx = getappdata(gcf,'PlotCondIdx');

  if ( plot_dims(1) < length(cond_idx) )
     set_cond_slider;
  end;

  return; 					% setup_sliders


%--------------------------------------------------------------------------
%
function set_cond_slider()
%
   ax_pos = getappdata(gcf,'AxesPos');
   [rows cols] = size(ax_pos);

   pos = ax_pos{rows,cols};
   pos_h = ax_pos{1,cols};

   x = pos(1)+pos(3)+0.05;
   y = pos(2);
   w = 0.02;
%   h = pos(4)*rows;
   h = pos_h(2)+pos_h(4)-pos(2);

   pos = [x y w h];

   cond_idx = getappdata(gcf,'PlotCondIdx');

   max_value = length(cond_idx) - rows + 1;
   value = max_value; 

   small_advance = 1/(max_value-1);

   big_advance = rows * small_advance;
   if (big_advance > 1), big_advance = 1; end;

   if (small_advance == big_advance)
      small_advance = small_advance - 0.00001; 
   end;
   slider_step = [small_advance big_advance];

   cb_fn=['fmri_plot_hrf({''MOVE_COND_SLIDE''})'];

   h_cond_bar = uicontrol('Parent',gcf, ... 
		   'Style', 'slider', ...
		   'Units', 'normal', ...
                   'Position', pos, ...
		   'Value', value, ...
		   'SliderStep', slider_step, ...
		   'Min', 1,  ...
		   'Max', max_value, ...
		   'Tag', 'ConditionSlider', ...
		   'Callback',cb_fn);
   
   return; 						% set_cond_slicer


%--------------------------------------------------------------------------
%
function plot_hrf(start_cond)

  combine_plots = getappdata(gcf,'CombinedPlots');

  evt_onsets = getappdata(gcf,'evt_onsets');
  win_size = getappdata(gcf,'win_size');

  x1 = getappdata(gcf,'x1');
  y1 = getappdata(gcf,'y1');
  x2 = getappdata(gcf,'x2');
  y2 = getappdata(gcf,'y2');
  y22 = getappdata(gcf,'y22');

  ax_hdls = getappdata(gcf,'AxesHdls');
  ax_combine_hdls = getappdata(gcf,'AxesCombineHdls');
  show_avg = getappdata(gcf,'ShowAverage');
  condition = getappdata(gcf,'condition');
  plot_dims = getappdata(gcf,'PlotDims');
  cond_idx = getappdata(gcf,'PlotCondIdx');

  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;

  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;

  curr_row = 1;
  num_conds = length(cond_idx);

  for i=1:rows,

     if (i > num_conds) 
        break;
     end;

     curr_cond_idx = cond_idx(i);
     curr_cond_name = condition{curr_cond_idx};

     load('rri_color_code');

     %  plot the data within the current window 
     %
     if (combine_plots),	% plot same condition data in a single axes

        axes(ax_hdls{curr_row,1});
        set(ax_hdls{curr_row,1},'Visible','off');

        axes(ax_combine_hdls{curr_row});
        set(ax_combine_hdls{curr_row},'Visible','on');

        cdata = y1;
        y_range = [min(cdata(:)), max(cdata(:))];
        x_range = [min(x1(:)), max(x1(:))];

        hold on;
        for j=1:size(cdata,1)
           h = plot(x1,cdata(j,:));
           set(h,'color',color_code(j,:));
        end
        h = plot(x1,cdata(curr_cond_idx,:));
        set(h,'color',color_code(curr_cond_idx,:));
        hold off;

        axis([x_range(1) x_range(2) y_range(1) y_range(2)]);

        onsets = [];

        for j = 1:length(evt_onsets)
           onsets = [onsets evt_onsets{j}'];
        end

        onsets2 = []; % onsets + win_size - 1;
        onsets = unique(sort([onsets(:); onsets2(:)]));
        set(gca,'XTick',onsets,'ytick',[]);

        ylabel(curr_cond_name); 

        if (i == 1)
           title('Hemodynamic response for combined conditions');
        end

        set(get(gca,'title'),'fontsize',12)

     else

        axes(ax_combine_hdls{curr_row});
        set(ax_combine_hdls{curr_row},'Visible','off');

        axes(ax_hdls{curr_row,1});
        set(ax_hdls{curr_row,1},'Visible','on');

        cdata = y1(curr_cond_idx,:);
        y_range = [min(cdata(:)), max(cdata(:))];
        x_range = [min(x1(:)), max(x1(:))];

        if y_range(1) == y_range(2)
           y_range(1) = y_range(1) - 0.00001;
           y_range(2) = y_range(2) + 0.00001;
        end

        hold on;
        h = plot(x1,cdata);
        set(h,'color',color_code(curr_cond_idx,:));
        hold off;

        axis([x_range(1) x_range(2) y_range(1) y_range(2)]);

        onsets = evt_onsets{curr_cond_idx};
        onsets2 = []; % onsets + win_size - 1;
        onsets = unique(sort([onsets(:); onsets2(:)]));
        set(gca,'XTick',onsets,'ytick',[]);

        ylabel(curr_cond_name); 

        if (i == 1)
           title('Hemodynamic response for individual condition');
        end

        set(get(gca,'title'),'fontsize',12)

     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});
        set(ax_hdls{curr_row,avg_col},'Visible','on');

        cdata = [y2(curr_cond_idx,:); y22(curr_cond_idx,:)];
        y_range = [min(cdata(:)), max(cdata(:))];
        x_range = [min(x2(:)), max(x2(:))];

        if y_range(1) == y_range(2)
           y_range(1) = y_range(1) - 0.00001;
           y_range(2) = y_range(2) + 0.00001;
        end

        hold on;
        plot(x2, cdata(1,:), 'b--');

        if (combine_plots)
           plot(x2, cdata(2,:), 'r:');
        end
        hold off;

        axis([x_range(1) x_range(2) y_range(1) y_range(2)]);
        set(gca,'YAxisLocation','right','XTick',[1:2:x_range(end)],'ytick',[]);

        if (i == 1)
           title('Average');
        end

        set(get(gca,'title'),'fontsize',12)

     end

     curr_row = curr_row+1;

  end;

  setappdata(gcf,'start_cond',start_cond);

  return; 						% plot_hrf


%--------------------------------------------------------------

function delete_fig

   try
      load('pls_profile');
      pls_profile = which('pls_profile.mat');

      fmri_plot_hrf_pos = get(gcbf,'position');

      save(pls_profile, '-append', 'fmri_plot_hrf_pos');
   catch
   end

   return;						% delete_fig

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -