Prev: error in my program
Next: Batch of experiments
From: Jan Simon on 3 Jun 2010 10:21 Dear Henrik! > foo = rand(2000,1000); > size(foo) > whos foo > file = fopen('c:\speedtest.txt','at'); > for i=1:10 > tic > fprintf(file,'%g\n',foo); > toc > end > fclose(file); Using file in text mode on a Windows machinehas the effect, that writing a "\n" creates CHAR([13, 10]) in the file. But the file pointer in text mode files is advanced by 1 only! Therefore calling FSEEK and FTELL in text mode files needs additional work to distinguish between normal characters and line breaks. Therefore I prefer writing file in binary mode ever and define the line breaks explicitely, e.g. with FPRINTF(['%s', char([13, 10])], 'string'); Please try if the binary mode has any effects on your problem. An unresponsive Matlab is often caused by memory fragmentation. Example: for k = 1:1e6 a = rand(1000); end This might or might not reuse the memory occupied by the array "a". Then the pause is not connected to FCLOSE, but happens accidently at the same time. How do you know that the time is spent during FCLOSE? This test might be more equivalent to the original problem: function WriteTest t0 = now; file = fopen('c:\speedtest.txt', 'ab'); for i = 1:1000 a = rand(1, 1500); fprintf(file,'%g\n', a); end tic fclose(file); toc disp((now - t0) * 86400); return; This takes 3.8 seconds on my old 1.5GHz Pentium-M laptop for binary and text mode. FCLOSE uses 0.0004 seconds... I cannot find different times if the the file is existing before or freshly created. Perhaps the delay is caused by the license server of Matlab. The connection to the license server is not checked during a Matlab function runs. If a function runs for several days, this might confuse the server??? Good luck, Jan |