Home > matlabmk > add_sbjct_info.m

add_sbjct_info

PURPOSE ^

add_code_info() - Reads information about a subject (e.g., their age,

SYNOPSIS ^

function [new_info, info_names]=add_sbjct_info(sbjct_infofile,sbjct_id)

DESCRIPTION ^

 add_code_info() - Reads information about a subject (e.g., their age,
                   working memory span, etc...) from a text file and stores
                   the information as a vector that can be easily added to
                   existing epoch information in the function crw2set.m.


 Usage:
  >> [new_info, info_names]=add_code_info(sbjct_infofile,sbjct_id)

 Required Global Variable:
   VERBLEVEL         = matlabMK level of verbosity (i.e., tells functions
                        how much to report about what they're doing during
                        runtime)

 Inputs:
   sbjct_infofile     = the name of a space or tab delimited text file
                        containing numeric information about subjects
                        (e.g., age, working memory span).  The first
                        row of the file is a header line with a
                        one word description of each column in the
                        file. Each row below the headerline
                        corresponds to a different subject.  The
                        first column of the file provides an ID number/code
                        name for each participant.  Additional columns
                        specify numeric subject information.

   sbjct_id          = a string that identifies the subject.
                       The value of 'sbjct_id' must match one of the cells
                       in the first column of 'sbjct_infofile'.

 Outputs:
   new_info          = a vector of new event information that can
                        be appended to the existing blf info
                        matrix
   info_names        = a cell array of strings containing the
                        header information for each column of
                        sbjct_infofile. The first column of
                        sbjct_infofile is ignored since it should just
                        contain subject IDs.


 Additional Notes:

 Don't use parenthesis in column header names.  MATLAB interprets
 the name as a function call.

 Use NaN to fill cells for subjects that don't have a value for a
 particular column

 Author:
 David Groppe
 Kutaslab, 10/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [new_info, info_names]=add_sbjct_info(sbjct_infofile,sbjct_id)
0002 % add_code_info() - Reads information about a subject (e.g., their age,
0003 %                   working memory span, etc...) from a text file and stores
0004 %                   the information as a vector that can be easily added to
0005 %                   existing epoch information in the function crw2set.m.
0006 %
0007 %
0008 % Usage:
0009 %  >> [new_info, info_names]=add_code_info(sbjct_infofile,sbjct_id)
0010 %
0011 % Required Global Variable:
0012 %   VERBLEVEL         = matlabMK level of verbosity (i.e., tells functions
0013 %                        how much to report about what they're doing during
0014 %                        runtime)
0015 %
0016 % Inputs:
0017 %   sbjct_infofile     = the name of a space or tab delimited text file
0018 %                        containing numeric information about subjects
0019 %                        (e.g., age, working memory span).  The first
0020 %                        row of the file is a header line with a
0021 %                        one word description of each column in the
0022 %                        file. Each row below the headerline
0023 %                        corresponds to a different subject.  The
0024 %                        first column of the file provides an ID number/code
0025 %                        name for each participant.  Additional columns
0026 %                        specify numeric subject information.
0027 %
0028 %   sbjct_id          = a string that identifies the subject.
0029 %                       The value of 'sbjct_id' must match one of the cells
0030 %                       in the first column of 'sbjct_infofile'.
0031 %
0032 % Outputs:
0033 %   new_info          = a vector of new event information that can
0034 %                        be appended to the existing blf info
0035 %                        matrix
0036 %   info_names        = a cell array of strings containing the
0037 %                        header information for each column of
0038 %                        sbjct_infofile. The first column of
0039 %                        sbjct_infofile is ignored since it should just
0040 %                        contain subject IDs.
0041 %
0042 %
0043 % Additional Notes:
0044 %
0045 % Don't use parenthesis in column header names.  MATLAB interprets
0046 % the name as a function call.
0047 %
0048 % Use NaN to fill cells for subjects that don't have a value for a
0049 % particular column
0050 %
0051 % Author:
0052 % David Groppe
0053 % Kutaslab, 10/2009
0054 
0055 global VERBLEVEL
0056 
0057 new_info=[];
0058 info_names=[];
0059 
0060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0061 % LOAD INFORMATION ABOUT EACH SUBJECT FROM A TEXT FILE
0062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0063 VerbReport(sprintf('Getting information about subject from %s', ...
0064            sbjct_infofile), 1, VERBLEVEL);  
0065 [sub_fid, message]=fopen(sbjct_infofile,'r');
0066 if (sub_fid==-1)
0067     error('Cannot open file %s.  According to fopen: %s.\n',sbjct_infofile,message);
0068 else
0069   %read column headers
0070   txtline = fgetl(sub_fid);
0071   if (txtline==-1)
0072     error('File %s is empty.\n',sbjct_infofile);
0073   else
0074     %Read column header
0075     clear sub_col_hdrs;
0076     [sub_col_hdrs{1}, rmndr]=strtok(txtline);
0077     col_ct=1;
0078     fprintf('Subject ID column is: %s\n',sub_col_hdrs{1});
0079     while ~isempty(rmndr)
0080       col_ct=col_ct+1;
0081       [sub_col_hdrs{col_ct}, rmndr]=strtok(rmndr);
0082       fprintf('Column %d is: %s\n',col_ct,sub_col_hdrs{col_ct});
0083     end
0084         
0085     %Read subject information
0086     row_ct=1;
0087     while ~feof(sub_fid)
0088         txtline = fgetl(sub_fid);
0089         col_ct=1;
0090         while ~isempty(txtline)
0091             [neo_val, txtline]=strtok(txtline);
0092             if col_ct==1,
0093                 crnt_sub_id=neo_val;
0094             else
0095                 file_sub_info(row_ct,col_ct-1)=str2double(neo_val); %events that
0096                 %do not have a value for that column
0097                 %should be represented as NaN
0098                 if isempty(str2num(neo_val))
0099                     watchit(sprintf(['Subject info file %s appears to have a non-numeric entry at Subject %s, column %s.\n', ...
0100                         'When using crw2set only numeric values are permitted.  Use sbjct_info2set.m for non-numeric values.'], ...
0101                         sbjct_infofile,crnt_sub_id,sub_col_hdrs{col_ct}));
0102                 end
0103             end
0104             col_ct=col_ct+1;
0105         end
0106         if strcmpi(crnt_sub_id,sbjct_id)
0107             if isempty(new_info),
0108                 new_info=file_sub_info(row_ct,:);
0109                 %keep searching just in case the subject was entered more
0110                 %than once in the info file
0111             else
0112                 error('File %s has multiple entries for subject %s.  Only one row per subject is allowed.\n',sbjct_infofile,sbjct_id);
0113             end
0114         end
0115         row_ct=row_ct+1;
0116     end
0117     if isempty(new_info),
0118        error('Could not find subject %s in file %s.  A cell in the first column of %s should contain %s.\n',sbjct_id, ...
0119            sbjct_infofile,sbjct_infofile,sbjct_id);
0120     end
0121     
0122     %return all header names except for the first column
0123     info_names=cell(1,length(sub_col_hdrs)-1);
0124     for dg=1:(length(sub_col_hdrs)-1),
0125       info_names{dg}=sub_col_hdrs{dg+1};
0126     end
0127   end
0128   fclose(sub_fid);
0129 end
0130

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005