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

📄 bfm_input_run_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 4 页
字号:
%----------------------------------------------------------------------------
function delete_fig

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

       bfm_input_run_pos = get(gcbf,'position');

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

   try
      plot_hrf_fig = getappdata(gcbf,'plot_hrf_fig');
      close(plot_hrf_fig);
   catch
   end

   try
      plot_onset_fig = getappdata(gcbf,'plot_onset_fig');
      close(plot_onset_fig);
   catch
   end

   return;


%----------------------------------------------------------------------------
function status = EditLength(h_onset)

   status = 0;

   if ~exist('h_onset', 'var')
      h_onset = gcbo;
   end

   num_scans = str2num(get(findobj(gcf,'Tag','NumScansEdit'),'String'));

   if isempty(num_scans)
      errmsg = 'ERROR: Number of scans must be specified first';
      set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
      return;
   end;

   curr_run = getappdata(gcf,'CurrRun');
   curr_onsets = getappdata(gcf,'CurrOnsets');
   curr_length = getappdata(gcf,'CurrLength');
   top_onset_idx = getappdata(gcf,'TopOnsetIdx');
   row_idx = get(h_onset,'Userdata');
   onset_idx = top_onset_idx + row_idx - 1;
   onset_list = curr_onsets{onset_idx};

   if isempty(onset_list)
      set(h_onset,'String', '');
      length_list = [];
      errmsg = 'ERROR: Onsets must be specified first';
      set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
%      return;
   end

   blk_length = deblank(strjust(get(h_onset,'String'),'left'));

   % evaluate the matlab statement if the first character is '@'
   % '@@' - last matlab statement
   %
   if ~isempty(blk_length) & (blk_length(1) == '@')	% matlab statement
      cmd_str = blk_length(2:end);

      if isequal(cmd_str,'@'),           % display the last matlab statement
         cmd_str = getappdata(gcf,'LastCommand');	
         set(h_onset,'String', cmd_str);
         return;					
      else
         setappdata(gcf,'LastCommand',blk_length);
         cmd_str = strrep(cmd_str,'{run#}',num2str(curr_run));
         cmd_str = strrep(cmd_str,'{cond#}',num2str(onset_idx));
         length_list = eval(cmd_str,'[]')';
	 if isempty(length_list),
            errmsg = 'ERROR: Invalid MATLAB statement to generate the length.';
            set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
         end;
      end;
      set(h_onset,'String', Number2String(length_list));
   else
      length_list = str2num(blk_length)';
   end;

   if (length(blk_length) > 0) & isempty(length_list) 
      errmsg = 'ERROR: Invalid input length';
      set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
      return;
   end;

   if (length(find(length_list >= num_scans)) ~= 0),
      errmsg = 'ERROR: Cannot have an length larger than the number of scans';
      set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
      return;
   end;

   if ~isequal(length(length_list), length(onset_list))
      if length(length_list) == 1
         length_list = repmat(length_list,[length(onset_list),1]);
         set(h_onset,'String', Number2String(length_list));
      else
         set(h_onset,'String','');
         length_list = [];
         errmsg = 'ERROR: Number of block length should match number of block onsets';
         set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
%         return;
      end
   end

   curr_length{onset_idx} = length_list;

   setappdata(gcf,'CurrLength',curr_length);

   if get(findobj('tag','ReplicateLabel'),'value')
      run_info = getappdata(gcf,'SessionRunInfo');
      SaveRunInfo(curr_run);

      for i = 1:length(run_info)
         LoadRunInfo(i);
         setappdata(gcf,'CurrLength',curr_length);
         SaveRunInfo(i);
      end

      ShowRunInfo(curr_run);
   end

   status = 1;

   return;						% EditLength


%----------------------------------------------------------------------------
function status = is_same_across_run

   status = 1;

   run_info = getappdata(gcf,'SessionRunInfo');

   for i = 2:length(run_info)
      if ~isequal(run_info(1).blk_onsets, run_info(i).blk_onsets) | ...
	 ~isequal(run_info(1).blk_length, run_info(i).blk_length)

         status = 0;
         return;

      end
   end
   
   return;						% is_same_across_run


%----------------------------------------------------------------------------
function plot_hrf

   CurrOnsets = getappdata(gcf,'CurrOnsets');
   SessionConditions = getappdata(gcf,'SessionConditions');
   NumConditions = length(SessionConditions);

   h0 = gcf;
   plot_hrf_fig_name = [];

   try
      plot_hrf_fig_name = get(getappdata(h0,'plot_hrf_fig'),'name');
   catch
   end

   if ~isempty(plot_hrf_fig_name) & ...
	strcmp(plot_hrf_fig_name,'Hemodynamic Response Function Plot')
      msg = 'ERROR: HRF Plot window has already been opened.';
      msgbox(msg,'ERROR','modal');
   else
      h01 = fmri_plot_hrf(SessionConditions, CurrOnsets);
      if ~isempty(h01)
         setappdata(h0,'plot_hrf_fig',h01);
      end
   end

   return;						% plot_hrf


%----------------------------------------------------------------------------
function EditReplicate

   replicate_status = get(findobj('tag','ReplicateLabel'),'value');

   if replicate_status
      run_info = getappdata(gcf,'SessionRunInfo');
      curr_run = getappdata(gcf,'CurrRun');

      for i = 1:length(run_info)
         LoadRunInfo(i);
         setappdata(gcf,'CurrOnsets',run_info(curr_run).blk_onsets);
         setappdata(gcf,'CurrLength',run_info(curr_run).blk_length);
         SaveRunInfo(i);
      end

      ShowRunInfo(curr_run);
   end

   return;


%----------------------------------------------------------------------------
function plot_onset

   CurrOnsets = getappdata(gcf,'CurrOnsets');
   SessionConditions = getappdata(gcf,'SessionConditions');

   h0 = gcf;
   plot_onset_fig_name = [];

   try
      plot_onset_fig_name = get(getappdata(h0,'plot_onset_fig'),'name');
   catch
   end

   if ~isempty(plot_onset_fig_name) & ...
	strcmp(plot_onset_fig_name,'Onset Timing Plot')
      msg = 'ERROR: Onset Timing Plot window has already been opened.';
      msgbox(msg,'ERROR','modal');
   else
      h01 = fmri_plot_onset(SessionConditions, CurrOnsets);
      if ~isempty(h01)
         setappdata(h0,'plot_onset_fig',h01);
      end
   end

   return;


%----------------------------------------------------------------------------
function result = check_run_ok

   result=1;

   run_info = getappdata(gcf,'SessionRunInfo');

   for i=1:length(run_info)
      curr_run = run_info(i);

      if isempty(curr_run.data_path) | isempty(curr_run.data_files)
         result=0;
         errmsg = 'Data Directory and Data Files for all runs must be selected';
         set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
      end

      for j=1:length(curr_run.blk_onsets)
         if isempty(curr_run.blk_onsets{j})
            result=0;
            errmsg = 'All the Onsets field must be filled out';
            set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
         elseif isempty(curr_run.blk_length{j})
            result=0;
            errmsg = 'All the Length field must be filled out';
            set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
         elseif ~isequal(length(curr_run.blk_onsets{j}),length(curr_run.blk_length{j}))
            result=0;
            errmsg = 'Number of onsets and length are not match';
            set(findobj(gcf,'Tag','MessageLine'),'String',errmsg);
         end
      end
   end

   return;


%----------------------------------------------------------------------------
function LoadTxt

   [fn, pn] = uigetfile('*.txt', 'Load Onsets for this run');

   if isequal(fn, 0) | isequal(pn, 0)
      return;
   end;

   onset_file = fullfile(pn, fn);

   if ~CheckRunInfo
      return;
   end

   slider_hdl = findobj(gcf,'Tag','BlockOnsetSlider');
   curr_value = round(get(slider_hdl,'Max'));

   fid = fopen(onset_file, 'rt');
   app = getappdata(gcf);
   num_onset_disp = size(app.Onset_hlist,1);
   remain_cond = length(app.SessionConditions);

   breakwhile = 0;

   while remain_cond > num_onset_disp
      set(slider_hdl,'Value',curr_value);
      MoveSlider;

      for i=1:num_onset_disp
         onset = fgetl(fid);
         set(app.Onset_hlist(i,2), 'string', onset);

         if ~EditOnsets(app.Onset_hlist(i,2))
            breakwhile = 1;
            break;
         end

         onset = fgetl(fid);
         set(app.Onset_hlist(i,3), 'string', onset);

         if ~EditLength(app.Onset_hlist(i,3))
            breakwhile = 1;
            break;
         end
      end

      if breakwhile
         break;
      end

      remain_cond = remain_cond - num_onset_disp;
      curr_value = curr_value - num_onset_disp;
   end

   if remain_cond <= num_onset_disp
      set(slider_hdl,'Value',curr_value);
      MoveSlider;

      for i=1:remain_cond
         onset = fgetl(fid);
         set(app.Onset_hlist(i,2), 'string', onset);

         if ~EditOnsets(app.Onset_hlist(i,2))
            break;
         end

         onset = fgetl(fid);
         set(app.Onset_hlist(i,3), 'string', onset);

         if ~EditLength(app.Onset_hlist(i,3))
            break;
         end
      end
   end

   fclose(fid);

   return;


%----------------------------------------------------------------------------
function SaveTxt

   [fn, pn] = uiputfile('*.txt', 'Save Onsets for this run');

   if isequal(fn, 0) | isequal(pn, 0)
      return;
   end;

   onset_file = fullfile(pn, fn);

   if ~CheckRunInfo
      return;
   end

   slider_hdl = findobj(gcf,'Tag','BlockOnsetSlider');
   curr_value = round(get(slider_hdl,'Max'));

   fid = fopen(onset_file, 'wt');
   app = getappdata(gcf);
   num_onset_disp = size(app.Onset_hlist,1);
   remain_cond = length(app.SessionConditions);

   breakwhile = 0;

   while remain_cond > num_onset_disp
      set(slider_hdl,'Value',curr_value);
      MoveSlider;

      for i=1:num_onset_disp
         onset = get(app.Onset_hlist(i,2), 'string');
         fprintf(fid, '%s\n', onset);
         onset = get(app.Onset_hlist(i,3), 'string');
         fprintf(fid, '%s\n', onset);
      end

      remain_cond = remain_cond - num_onset_disp;
      curr_value = curr_value - num_onset_disp;
   end

   if remain_cond <= num_onset_disp
      set(slider_hdl,'Value',curr_value);
      MoveSlider;

      for i=1:remain_cond
         onset = get(app.Onset_hlist(i,2), 'string');
         fprintf(fid, '%s\n', onset);
         onset = get(app.Onset_hlist(i,3), 'string');
         fprintf(fid, '%s\n', onset);
      end
   end

   fclose(fid);

   return;

⌨️ 快捷键说明

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