MATLAB - delete binary file elements without downloading the entire file

This might be a dumb question, but Google docs and MATLAB let me down. I have a fairly large binary (> 10 GB) that I need to open and delete the last forty million bytes. Is there a way to do this without reading the entire file in memory in chunks and printing it to a new file? It took 6 hours to generate the file, so I come up with the idea of ​​re-reading all of this.

EDIT:

The file size is 14,440,000,000 bytes. I need to chop it off to 14.4 billion.

+5
source share
4 answers

I found that Perl is much faster than MATLAB.

Perl Cookbook:

truncate(HANDLE, $length)
    or die "Couldn't truncate: $!\n";

truncate("/tmp/$$.pid", $length)
    or die "Couldn't truncate: $!\n";

Perl script MATLAB PERL.

+4

Matlab ftruncate(), Java- JVM, Matlab, java.io.RandomAccessFile Java NIO .

Matlab, Java, n . -.

function remove_last_n_bytes_from_file(file, n)

jFile = java.io.RandomAccessFile(file, 'rw');
currentLength = jFile.length();
wantLength = currentLength - n;
fprintf('Truncating file %s: Resizing to %d to remove %d bytes\n', file, wantLength, n);
jFile.setLength(wantLength);
jFile.close();

.

java.io.RandomAccessFile('/path/to/my/file.bin', 'rw').setLength(n);
+5

MATLAB (), . MATLAB , "system"

system

, , . , truncate() (unix - KennyTM) SetEndOfFile (windows)

+2

I don't know if MATLAB supports this, but see ftruncate()andtruncate() .

0
source

All Articles