FWIW, below, this is some code to reproduce this problem:
fids = zeros(1,513); for ix = 1:length(fids) fids(ix) = fopen(sprintf('testfile_%03d.tmp',ix),'w'); end fids(507:end)
(After this, basic commands such as "help" fail, you need to run fclose all ).
A little web search attracts other people (in the worst Q&A forums) with the same problems, but without simple solutions (for example, this is a Mathworks forum post .)
My first instinct, when I encounter the limitations of Matlab, is to always turn to Java. For instance:
streamwriters = cell(1,513); for ix = 1:length(streamwriters) strName = sprintf('testfile_2_%03d.tmp',ix); streamwriters{ix} = java.io.FileOutputStream(strName); end streamwriters{513}.write(uint8('Some data to write'))
When you make a Java call from Matlab, you are standing (I think for a few ms), so you really do 1,000,000 entries, I would profile your code and look for ways to collect the code in memory and execute smaller, larger batches if necessary.
Also remember that you need to close them separately, for example.
for ix = 1:length(streamwriters) streamwriters{ix}.close(); end