While we do not have any built-in routines in our products to do specifically what you want, you may be able to write a MATLAB function that does this.
You will need to do something along the lines of the following:
1. Open a temporary file (see "doc tempname")
2. Write your data there that you wish to prepend
3. Open your original file for reading
4. Read from your original and write to the temporary file
5. Close both files
6. Copy the temporary over the original (see "doc copyfile")
An example is shown below.
function prepend2file( string, filename, newline )
tempFile = tempname
fw = fopen( tempFile, 'wt' );
if nargin < 3
newline = false;
end
if newline
fwrite( fw, sprintf('%s\n', string ) );
else
fwrite( fw, string );
end
fclose( fw );
appendFiles( filename, tempFile );
copyfile( tempFile, filename );
delete(tempFile);
function status = appendFiles( readFile, writtenFile )
fr = fopen( readFile, 'rt' );
fw = fopen( writtenFile, 'at' );
while feof( fr ) == 0
tline = fgetl( fr );
fwrite( fw, sprintf('%s\n',tline ) );
end
fclose(fr);
fclose(fw);