When writing a large array directly to disk in MATLAB, is there any need to preallocate?
I need to write an array that is too large to fit into memory to a .mat binary file. This can be accomplished with the matfile function, which allows random access to a .mat file on disk. Normally, the accepted advice is to preallocate arrays, because expanding them on every iteration of a loop is slow. However, when I was asking how to do this , it occurred to me that this may not be good advice when writing to disk rather than RAM. Will the same performance hit from growing the array apply , and if so, will it be significant when compared to the time it takes to write to disk anyway? (Assume