function asc2mat(num) filtm = ['/local_mount/space/doodles/1/users/MTstudy/MEG/blockDesign/subj_0' num '/anal/testave'] d= dir([filtm '/*.asc']) for kjump=1:length(d) fname=fullfile(filtm,d(kjump).name); fid = fopen(fname); [mpath,mname] =fileparts(fname); newmfile = fullfile(mpath,[mname '.mat']); notYet = 1; while notYet == 1 thisLine = fgetl(fid); check = strfind(thisLine,'channels:'); if ~isempty(check) notYet=0; end end count =0; moreLeft=1; chancount = 0; while moreLeft==1 thisLine = fgetl(fid); if isempty(thisLine) | thisLine==-1 moreLeft=0; elseif thisLine(1)=='#' vals = sscanf(thisLine(2:end),'%s %d'); ind = 1; for i=1:length(vals)/4 cname(chancount + i) = {char([vals(ind:ind+2)]')}; cnum(chancount + i) = vals(ind+3); ind = ind + 4; end chancount = chancount + length(vals)/4; notStarted = 1; elseif notStarted==1 times = sscanf(thisLine,'%f'); notStarted=0; else count = count+1; datavals(count) = {sscanf(thisLine,'%f')}; end end fclose(fid); save(newmfile,'cname','cnum','datavals','times') end if 0 inds = find(strcmp(a.cname,'MEG')); figure hold on RMS = zeros(length(times),1); for i=1:length(inds) plot(times,datavals{inds(i)}); RMS = RMS + datavals{inds(i)}.^2; end RMS = sqrt(RMS/length(inds)); plot(times,RMS,'r') hold off end