eeg_write_ascii - Write matrix of EEG data into ascii data format Useage: eeg_write_ascii(file,data,format) where: file is the path + filename, eg "c:\data.dat" data is a data matrix (floating point) format is an fprintf format string ('%12.6f' default) comment: Uses the fprintf method, which is quicker than the dlmwrite() function. It remains to be seen whether it is quicker or provides more format options than the built-in SAVE function.
0001 function eeg_write_ascii(file,data,format) 0002 0003 % eeg_write_ascii - Write matrix of EEG data into ascii data format 0004 % 0005 % Useage: eeg_write_ascii(file,data,format) 0006 % 0007 % where: file is the path + filename, eg "c:\data.dat" 0008 % data is a data matrix (floating point) 0009 % format is an fprintf format string ('%12.6f' default) 0010 % 0011 % comment: Uses the fprintf method, which is quicker than the 0012 % dlmwrite() function. It remains to be seen whether it 0013 % is quicker or provides more format options than the 0014 % built-in SAVE function. 0015 % 0016 0017 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $ 0018 0019 % Licence: GNU GPL, no express or implied warranties 0020 % History: 07/2001, Darren.Weber_at_radiology.ucsf.edu 0021 % 0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0023 0024 if ~exist('format','var') format = '%12.6f'; end 0025 0026 % transpose data for output, see note below 0027 data = data'; 0028 0029 [r,c] = size(data); % size of matrix: r rows and c columns 0030 0031 % create a format string long enough to provide a format for every 0032 % row of the data - put a line return at the end of this string 0033 formats = ''; 0034 for i = 1:r 0035 formats = strcat(formats, ' ', format); 0036 end 0037 formats = strcat(formats,'\n'); 0038 0039 % Output data 0040 fid = fopen(file,'w'); fprintf(fid,formats,data); fclose(fid); 0041 0042 fprintf('Completed ascii write to:\t%s\n', file); 0043 return 0044 0045 0046 0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 % NOTE on TRANSPOSE 0049 % this routine transposes in the input data matrix to 0050 % accommodate the matlab fprintf routine, which outputs in 0051 % column major format to effectively transpose the input. For 0052 % example, 'help fprintf' provides this example: 0053 % 0054 % x = 0:.1:1; y = [x; exp(x)]; 0055 % fprintf('%6.2f %12.8f\n',y); 0056 % 0057 % where y is a 2row, 11 column matrix and the output is: 0058 % 0059 % 0.00 1.00000000 0060 % 0.10 1.10517092 0061 % ... 0062 % 1.00 2.71828183 0063