Friday, November 16, 2012

Matlab save binary files

%write
tic
file = fopen('test.binm', 'w');
a = ones(200, 10);
a = cumsum(a);
fwrite(file, a', 'double');
fclose(file);
clear a;


for i=1:100
%append
    a = ones(1, 10)*i;
    file = fopen('test.binm', 'a');
    fwrite(file, a, 'double');
    fclose(file);
    clear a;
end

%read
file = fopen('test.binm', 'r');
a = fread(file,[10,300], 'double')';
fclose(file);

toc

No comments:

Post a Comment