Home > matlabmk > chanlocs_from_crw_erpio2.m

chanlocs_from_crw_erpio2

PURPOSE ^

function use_chanlocs=chanlocs_from_crw(crwfile,exclude_chans,include_chans)

SYNOPSIS ^

function use_chanlocs=chanlocs_from_crw(crwfile,exclude_chans,include_chans)

DESCRIPTION ^

function use_chanlocs=chanlocs_from_crw(crwfile,exclude_chans,include_chans)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function use_chanlocs=chanlocs_from_crw(crwfile,exclude_chans,include_chans)
0002 %function use_chanlocs=chanlocs_from_crw(crwfile,exclude_chans,include_chans)
0003 
0004 global VERBLEVEL;
0005 
0006 if ~isempty(exclude_chans) && ~isempty(include_chans)
0007     error('You can''t use both "exclude_chans" and "include_chans" input arguments.');
0008 end
0009 
0010 %fid_crw=erpio('openraw',crwfile,logfile,presam,cprecis,decimat);
0011 %if (erpio('get_errno') == 0),
0012 %    VerbReport(sprintf('Opening crw file %s went OK', crwfile), 3, VERBLEVEL);
0013 %else
0014 %    err_msg=erpio('get_errstr');
0015 %    erpio('close',fid_crw);
0016 %    error(err_msg);
0017 %end
0018 
0019 n_chans=erpio2('get_nchans',crwfile);
0020 errstring=erpio2('get_errstr'); % check for error
0021 if ~isempty(errstring),
0022    error(errstring); 
0023 end
0024 
0025 %Try to create chanlocs from library of locations for initial
0026 %subject
0027 if n_chans>=59,
0028     %Try to match with 59 channel cap "chanlocs" variable
0029     load('/usr/local/matlab-toolboxes/matlabmk/mk66locs');
0030 else
0031     %Try to match with 26 channel cap "chanlocs" variable
0032     load('/usr/local/matlab-toolboxes/matlabmk/mk33locs');
0033 end
0034 n_chanlocs=length(chanlocs);
0035 crw_chanlabels=cell(1,n_chans);
0036 used_chan_ct=0;
0037 excluded_chan_ct=0;
0038 use_chans=zeros(1,n_chans); %keep track of which channels should be included
0039 for c=1:n_chans,
0040     chan_label=erpio2('get_chandes',crwfile,c-1);
0041     errstring=erpio2('get_errstr'); % check for error
0042     if ~isempty(errstring),
0043         error(errstring);
0044     end    
0045     crw_chanlabels{c}=chan_label;
0046     use_chans(c)=1; %assume the channel will be included by default
0047     if ~isempty(exclude_chans) && ismember(chan_label,exclude_chans),
0048         excluded_chan_ct=excluded_chan_ct+1;
0049         excluded_chans{excluded_chan_ct}=chan_label;
0050         use_chans(c)=0;
0051     end
0052     if ~isempty(include_chans) && ~ismember(chan_label,include_chans),
0053         use_chans(c)=0;
0054     end
0055     if use_chans(c),
0056         used_chan_ct=used_chan_ct+1;
0057         %Standardize Channel Names
0058         if strcmpi(chan_label,'lle'),
0059             avg_label='LLEy';
0060         elseif strcmpi(chan_label,'rle'),
0061             avg_label='RLEy';
0062         elseif strcmpi(chan_label,'lhe') || strcmpi(chan_label,'lhz') || ...
0063                 strcmpi(chan_label,'lhrz'),
0064             avg_label='LHEy';
0065         elseif strcmpi(chan_label,'rhe') || strcmpi(chan_label,'rhz') || ...
0066                 strcmpi(chan_label,'rhrz'),
0067             avg_label='RHEy';
0068         elseif strcmpi(chan_label,'HE'),
0069             avg_label='HEOG';
0070         elseif strcmpi(chan_label,'VE'),
0071             avg_label='VEOG';
0072         else
0073             avg_label=chan_label;
0074         end
0075         found=0;
0076         for d=1:n_chanlocs,
0077             if strcmpi(avg_label,chanlocs(d).labels),
0078                 if used_chan_ct==1,
0079                     use_chanlocs=chanlocs(d); %create new struct
0080                 else
0081                     use_chanlocs(used_chan_ct)=chanlocs(d);
0082                 end
0083                 use_chanlocs(used_chan_ct).labels=chan_label;
0084                 found=1;
0085             end
0086         end
0087         if ~found,
0088             watchit(sprintf(['Could not find a default coordinate for channel %s. ' ...
0089                 'Giving it the bogus coordinate of a few inches in front of the nose.\n'],chan_label));
0090             use_chanlocs(used_chan_ct)=chanlocs(n_chanlocs); %the last electrode should be VEOG
0091             use_chanlocs(used_chan_ct).labels=chan_label;
0092         end
0093     end
0094 end
0095 
0096 use_chan_labels=cell(1,used_chan_ct);
0097 for d=1:used_chan_ct,
0098     use_chan_labels{d}=use_chanlocs(d).labels;
0099 end
0100 
0101 % Figure out if any channels were missed
0102 if ~isempty(exclude_chans),
0103     missing=setdiff(exclude_chans,excluded_chans);
0104     err_msg=sprintf('You asked to exclude the following channels but they are not in %s:',crwfile);
0105     for a=1:length(missing),
0106        err_msg=[err_msg ' ' missing{a}]; 
0107     end
0108     if ~isempty(missing),
0109         watchit(err_msg);
0110     end
0111 elseif ~isempty(include_chans),
0112     missing=setdiff(include_chans,use_chan_labels);
0113     err_msg=sprintf('You asked to include the following channels but they are not in %s:',crwfile);
0114     for a=1:length(missing),
0115        err_msg=[err_msg ' ' missing{a}]; 
0116     end
0117     if ~isempty(missing),
0118         watchit(err_msg);
0119     end
0120 end

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