Last active
August 29, 2015 14:19
-
-
Save czarrar/2f45d6a8b1efb94f0d44 to your computer and use it in GitHub Desktop.
Convert grand average file generated by mipgav4 into multiple csv files. Please note that you will also need the `csvwrite_with_headers` (if you don't already have it). It can be found here: http://www.mathworks.com/matlabcentral/fileexchange/29933-csv-with-column-headers/content/csvwrite_with_headers.m.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function write_gav2csv(infile, outprefix, smoothOn) | |
% WRITE_GAV2CSV Write the grand-average file as a CSV | |
% write_gav2csv(infile, outfile) | |
% | |
% infile : Input grand average file name (e.g., 'myfile.gav') | |
% outprefix : Prefix to output (e.g., 'myfile'). A separate file will be created corresponding to each bin. | |
% smoothOn : 0 means no smoothing. 1 [default] = single smoothing. 2 = double smoothing, etc. | |
% | |
% Created by Zarrar Shehzad on 2015-04-23. | |
if nargin < 3 | |
smoothOn = 1; | |
end | |
% If don't want to use the whole function business | |
% Then you can skip the above part and set the following three values given below | |
% and then copy and paste all the code that follows | |
% | |
% infile = 'xxx'; % of course replace with your own stuff | |
% outprefx = 'yyyy'; | |
% smoothOn = 2; | |
% Read in the data | |
fprintf('reading in data\n'); | |
hdr = EEGRead2(infile); | |
dat = hdr.data; | |
% Get the time-points | |
tpts = -hdr.onset:hdr.sampling:(hdr.nPoints*hdr.sampling-hdr.onset-1); | |
% Smooth data (if asked) | |
if smoothOn > 0 | |
fprintf('smoothing data\n'); | |
for so = 1:smoothOn | |
for ibin = 1:size(dat,1) | |
for ichan = 1:size(dat,2) | |
dat(ibin,ichan,:) = smooth(tpts, dat(ibin,ichan,:)); | |
end | |
end | |
end | |
end | |
% Save the data by bin | |
for ibin = 1:size(dat,1) | |
binName = hdr.binNames{ibin}; | |
outfile = strcat(outprefix, '_', binName, '.csv'); | |
fprintf('saving %s\n', outfile); | |
binDat = squeeze(dat(ibin,:,:)); | |
binDat = [tpts; binDat]'; | |
headers = [{'time'}; hdr.chanNames]; | |
csvwrite_with_headers(outfile, binDat, headers); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment