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

📄 erp_showplot_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 3 页
字号:
%ERP_SHOWPLOT_UI display ERP waveforms on a figure
%
%  USAGE: erp_showplot_ui(fig)
%
%   ERP_SHOWPLOT_UI(fig) will display ERP waveforms on 'fig'.
%

%   Called by ERP_PLOT_UI, ERP_PLOT_OPTION_UI
%
%   I (fig) - figure where ERP waveform will be displayed on
%
%   Created on 25-NOV-2002 by Jimmy Shen
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function erp_showplot_ui(fig)

   if ~exist('fig','var')
      fig = gcf;
   end

   system = getappdata(fig,'system');
   time_info = getappdata(fig,'time_info');

   timepoint = round(time_info.timepoint);
   start_timepoint = floor(time_info.start_timepoint);
   start_time = time_info.start_time;
   end_time = time_info.end_time;
   digit_interval = time_info.digit_interval;

   init_option = getappdata(fig,'init_option');

   if isempty(init_option)
      init_flag = 1;
   else
      init_flag = 0;
   end

   ha = getappdata(fig,'ha');			% main axes
   hm_chan_name = getappdata(fig,'hm_chan_name');
   need_chan_name = get(hm_chan_name,'userdata');
   hm_chan_axes = getappdata(fig,'hm_chan_axes');
   need_chan_axes = get(hm_chan_axes,'userdata');
   hm_chan_tick = getappdata(fig,'hm_chan_tick');
   need_chan_tick = get(hm_chan_tick,'userdata');

   font_size_list = [6 8 10 11 12 14 16 18];

   if(init_flag)				%% if first time run showplot

      % close detail window particularly for rescale
      %
      hm_detail = getappdata(fig,'hm_detail');
      set(hm_detail, 'userdata',0, 'check','off');

      try
         detail_fig_name = get(getappdata(gcf,'detail_fig'),'user');
         if ~isempty(detail_fig_name) & strcmp(detail_fig_name,'Detail Plot')
            close(getappdata(gcf,'detail_fig'));
         end
      catch
      end

      %  delete possible old_legend
      %
      old_legend_hdl = getappdata(fig,'legend_hdl');
      if ~isempty(old_legend_hdl)
         try
            delete(old_legend_hdl{1});
            hm_legend = getappdata(fig,'hm_legend');
            setappdata(fig,'legend_hdl',[]);
            set(hm_legend,'Userdata',1,'Label','&Legend on');
         catch
         end
      end

      old_txtbox_hdl = getappdata(fig,'txtbox_hdl');
      if ~isempty(old_txtbox_hdl)
         try
            delete(old_txtbox_hdl);
            setappdata(fig,'txtbox_hdl',[]);
         catch
         end
      end

      view_option = getappdata(fig,'view_option');
      color_code = getappdata(fig,'color_code');	% color & linestyle
      bs_color_code = getappdata(fig,'bs_color_code');

      wave_selection = getappdata(fig,'wave_selection');
      avg_selection = getappdata(fig,'avg_selection');
      bs_selection = getappdata(fig,'bs_selection');

      wave_selection(find(wave_selection==0)) = [];
      avg_selection(find(avg_selection==0)) = [];
      bs_selection(find(bs_selection==0)) = [];

      color_selection = 1:(length(wave_selection)+length(avg_selection));
      bs_color_selection = 1:length(bs_selection);

      if length(color_selection) > length(color_code)	% need more color

         tmp = [];

         for i=1:ceil( length(color_selection)/length(color_code) )
            tmp = [tmp; color_code];
         end

         color_code = tmp;

      end

      if length(bs_color_selection)>length(bs_color_code)  % need more color

         tmp = [];

         for i=1:ceil( length(bs_color_selection)/length(bs_color_code) )
            tmp = [tmp; bs_color_code];
         end

         bs_color_code = tmp;

      end

      x_interval_selection = getappdata(fig,'x_interval_selection');
      y_interval_selection = getappdata(fig,'y_interval_selection');

      %  display wave size scale, from 0.05 to 1, 1 means full screen
      %
      eta = getappdata(fig,'eta');

      %  font size
      %
      font_size = font_size_list(getappdata(fig,'font_size_selection'));

      color_code1 = color_code(1:length(avg_selection),:);
      color_code2 = color_code((length(avg_selection)+1): ...
				length(color_selection),:);
      color_code3 = bs_color_code(1:length(bs_selection),:);

      wave_amplitude = getappdata(fig,'brain_amplitude'); % input wave

      rescale = getappdata(fig,'rescale'); % Scale by Singular Value
      s = getappdata(fig,'s'); % Singular Value

      if rescale
         for i=1:length(s)
            wave_amplitude(:,:,i) = wave_amplitude(:,:,i).*s(i);
         end
      end

      wave_name = getappdata(fig,'wave_name');		% wave legend

      selected_wave_info = getappdata(fig,'selected_wave_info');
			% [condition(selected), subjects(selected)]

      selected_wave = getappdata(fig,'selected_wave');	% based on
					% selected_cond & selected_subj
      selected_wave_idx = selected_wave(wave_selection);

      selected_channels = getappdata(fig,'selected_channels');
      selected_chan_idx = find(selected_channels);

      wave_disp = wave_amplitude(:,selected_chan_idx,selected_wave_idx);

      selected_wave_name = wave_name(selected_wave_idx);
      selected_wave_name = char(selected_wave_name);	% legend string
      num_wave = size(selected_wave_name,1);		% # of wave to display

      avg_amplitude = getappdata(fig,'avg_amplitude');	% input avg
      avg_name = getappdata(fig,'avg_name');		% avg legend

      if ~isempty(avg_amplitude)
         selected_avg = find(getappdata(fig,'selected_conditions'));
         selected_avg_idx = selected_avg(avg_selection);
         avg_disp = avg_amplitude(:,selected_chan_idx,selected_avg_idx);
         selected_avg_name = avg_name(selected_avg_idx);
      else
         selected_avg = [];
         selected_avg_idx = [];
         avg_disp = [];
         selected_avg_name = [];
      end

      selected_avg_name = char(selected_avg_name);
      num_avg = size(selected_avg_name,1);

      bs_amplitude = getappdata(fig,'bs_amplitude');	% input bootstrap
      bs_name = getappdata(fig,'bs_name');		% bs legend

      if ~isempty(bs_amplitude)

         bs_x_amplitude = bs_amplitude;
         selected_bs = getappdata(fig,'selected_bs');	% 1 to lv
         num_lv = length(selected_bs);

         % re-order the LV sequence, so that LV1 will be put on top,
         % LV2 will be put on bottom, LV3 will be put next top, ...
         %
         bs_y_amplitude = [];
         for i = 1:ceil(num_lv / 2)
            bs_y_amplitude = [bs_y_amplitude, num_lv-i+1];
            if (num_lv - i + 1) ~= i
               bs_y_amplitude = [bs_y_amplitude, i];
            end
         end

         % normalize the new order, and reshape it to the required
         % y direction vector for bootstrap
         %
         if num_lv > 1
            bs_y_amplitude = (bs_y_amplitude - 1) / (num_lv - 1);
         end;

         bs_y_amplitude = reshape(bs_y_amplitude, [1,1,num_lv]);
         bs_y_amplitude = repmat(bs_y_amplitude, ...
				[timepoint, size(bs_amplitude, 2)]);

         selected_bs_idx = selected_bs(bs_selection);
         selected_bs_name = bs_name(selected_bs_idx);

      else
         bs_y_amplitude = [];
         selected_bs_idx = [];
         bs_x_amplitude = [];
         selected_bs_name = [];
      end

      selected_bs_name = char(selected_bs_name);
      num_bs = size(selected_bs_name,1);

      if ~isempty(wave_disp)
         wave_max = max(wave_disp(:));
         wave_min = min(wave_disp(:));
      else
         wave_max = 0;
         wave_min = 0;
      end

      if ~isempty(avg_disp)
         avg_max = max(avg_disp(:));
         avg_min = min(avg_disp(:));
      else
         avg_max = 0;
         avg_min = 0;
      end

      wave_top = max(wave_max, avg_max);		% top end of y axis
      if wave_max < 0
         wave_top = 0;
      end

      wave_bottom = min(wave_min, avg_min);		% bottom end of y axis
      if wave_min > 0
         wave_bottom = 0;
      end

      if wave_top + wave_bottom == 0
         msg = 'ERROR: No wave to display.';
         uiwait(msgbox(msg,'ERROR','modal'));
         return;
      end

      if view_option == 3
         north = [sprintf('%0.2f',wave_top)];
         south = [sprintf('%0.2f',wave_bottom)];
      else
         north = [sprintf('%0.2f',wave_top) ' \muV'];
         south = [sprintf('%0.2f',wave_bottom) ' \muV'];
      end

      west = sprintf('%d ms', start_timepoint * digit_interval);	
%      east = sprintf('%d ms', (start_timepoint+timepoint-1) * digit_interval);
      east = sprintf('%d ms', (start_timepoint+timepoint) * digit_interval);

      %  belows are 4 lines represent the channel axis
      %
      hor_x = [0 1];
      hor_y = [0 0];

      if start_timepoint < 0
         ver_x = ((-start_timepoint)/(timepoint-1)) * [1 1];
      else
         ver_x = [0 0];
      end

      ver_y = [wave_bottom wave_top] / (wave_top - wave_bottom);

      xtick_length = 1/40;

      if start_timepoint < 0
         xtick_x = ((-start_timepoint)/(timepoint-1)) * [1 1];
      else
         xtick_x = [0 0];
      end

      xtick_y = [-xtick_length xtick_length];

      ytick_length = 1/80;

      if start_timepoint < 0
         ytick_x = ((-start_timepoint)/(timepoint-1))+ ...
				[-ytick_length ytick_length];
      else
         ytick_x = [-ytick_length ytick_length];
      end

      ytick_y = [0 0];

      % ------------------- below: set waveform origin -------------

      switch system.class
         case 1
            type_str = 'BESAThetaPhi|EGI128|EGI256';

            switch system.type
               case 1
                  load('erp_loc_besa148');
               case 2
                  load('erp_loc_egi128');
               case 3
                  load('erp_loc_egi256');
            end
         case 2
            type_str = 'CTF-150';

            switch system.type
               case 1
                  load('erp_loc_ctf150');
            end
      end

      x = chan_loc(:,1);
      y = chan_loc(:,2);

      min_x = min(x);	max_x = max(x);
      min_y = min(y);	max_y = max(y);

      % apply channel mask
      %
      chan_mask = getappdata(fig,'chan_mask');
      chan_nam = chan_nam(chan_mask,:);
      chan_loc = chan_loc(chan_mask,:);

      for i=selected_chan_idx
         x(i) = chan_loc(i,1);
         y(i) = chan_loc(i,2);
      end

      % normalize & shift x & y array
      %
      x = ((x-min_x) / (max_x-min_x))*0.95+0.05;
      y = ((y-min_y) / (max_y-min_y))*0.9;

      % ------------------- above: set waveform origin -------------

      % ------------------- below: start to draw axes & wave -------------

      if ~isempty(wave_disp) | ~isempty(avg_disp)  %  there is wave

         axes(ha); cla;
         hold on;

         %  create template for sub axis
         %
         axis_template = plot(hor_x,hor_y,'k-',ver_x,ver_y,'k-', ...
            'visible','off');
         xtick_template_hdl = plot(xtick_x,xtick_y,'k-', ...
            'visible','off');
         ytick_template_hdl = plot(ytick_x,ytick_y,'k-', ...
            'visible','off');

         % xtick

⌨️ 快捷键说明

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