Thanks a lot for your response!
I am shamefully a beginning user of Matlab with no programming knowledge.
My friend wrote me the following script to take off the first two lines.
I guess that just a few changes to the script will make it read files from line 51 to line 450. However, I do not know how to twist it :(
Below is the script:
function filt
% Define parameters
path = '/Users/yuy3/Documents/MATLAB/PCA_CSD/Yan_diss_CSD_mul_all/mms'; % The folder contains data
overwrite = true; % Whether overwrite the data file, if not, a new data file with surffix '.new' will be written
% Search the directory to find all files
namelist = dir_search( path, char( '') );
for it = 1 : size(namelist,1)
% Form the name of the source file and the destination file
source = deblank( namelist( it, : ) );
if isempty( source )
continue
end
if overwrite
dest = source;
else
dest = sprintf( '%
s.new', source );
end
% Read file, and filter it
file_filt( source, dest );
end
end
% Search directory
function newlist = dir_search( path, namelist )
% Read directory
direnv = dir(path);
newlist = namelist;
for it = 1 : size(direnv,1)
fname = direnv(it).name;
% Skip the parent directory and the directory itself
if strcmp( fname, '.' )
continue
end
if strcmp( fname, '..' )
continue
end
fullname = sprintf( '%s/%s', path, fname );
if isdir( fullname )
% If this is a directory, search it recursively
newlist = char( newlist, dir_search( fullname, char('') ) );
else
% If this is a file, add the name into list
newlist = char( newlist, fullname );
end
end
end
% File filter
function file_filt ( source, dest )
% Read source file
fid = fopen( source, 'rb' );
data = char( '' );
dummy = fgets( fid ); % Skip the first line
dummy = fgets( fid ); % Skip the second line
x = fgets( fid );
while ischar( x )
% Read the following lines
data = char( data, x );
x = fgets( fid );
end
fclose( fid );
% Write destination file
fid = fopen( dest, 'wb' );
for it = 2 : size( data, 1 )
x = deblank( data( it, : ) );
% Write each line, add return and enter at the end of line except
% the last line
if ( it < size( data, 1 ) )
fprintf( fid, '%s\r\n', x );
else
fprintf( fid, '%s', x );
end
end
fclose( fid );
end
Again, thanks a ton!
Yan
dpb <
no...@non.net> wrote in message <knl5or$f3i$
1...@speranza.aioe.org>...