I have a huge data set that I'm caching, then writing filtered analysis data to disk. I have various disp()
commands in my code, along with fprintf()
calls.
I'd like to see the results both in the file, and on the screen while the processes are running, but what I'm finding is that I get nothing until I terminate the program, at which point all the data is written into my file and the disp()
floods the terminal.
Would there be a way to force disp()
and the fprintf()
to execute as they're being processed??
Here's an example:
function one(varargin)
setenv GNUTERM 'x11';
dirname = strcat(pwd, '/fileset');
files = dir(dirname);
disp('reading directory'), disp(dirname);
fileidx = find(~[files.isdir]);
out = fopen('write_data.txt', 'w');
fprintf(out, '"--- var a[0]", "--- var [1]";\n');
numfiles = length(fileidx);
for i = 1:numfiles
dispstring = sprintf('processing file %d of %d...', i, numfiles);
disp(dispstring);
filename = [dirname, '/', files(fileidx(i)).name];
disp(filename);
fid = fopen(filename, 'r');
%some processing here to obtain timevalues and maxvars
for i = 1:length(timevalues)
fprintf(out, '%d, %d;\n', timevalues(i), maxvars(i));
end
end
fclose(out);
end
I saw this post, but I wasn't sure which of the methods suggested applied to me. It also seemed like fflush()
was meant for pushing data into a plot at higher priority.