I am using Matlab to invoke some external call in C++ and then receive a huge calculated matrix back. The matrix is very huge, and I do not have access to this C++ program's source code. (if I have, I will make it save from C++ right away)
Right now, on my system, this C++ program only uses 1 second to calculate the given data and send back to Matlab, and Matlab's dlmwrite takes 200-300 seconds to save this single huge array on disk. I have some more thousands to compute, and I wanna cut the time down.
So what is the fastest way possible to save in Matlab?
Select MATLAB > General > MAT-Files and then choose a MAT-file save format option.
Use the matfile function to access MATLAB® variables directly from MAT-files on disk, without loading the full variables into memory. When you create a new file using matfile , the function creates a Version 7.3 MAT-file that also lets you save variables larger than 2 GB.
A slow startup is often caused by issues with the license search path. You probably need to adjust one of the license environment variables (LM_LICENSE_FILE or MLM_LICENSE_FILE) used by MATLAB, or else bypass them all together.
To save variables to a MATLAB script, click the Save Workspace button or select the Save As option, and in the Save As window, set the Save as type option to MATLAB Script. Variables that cannot be saved to a script are saved to a MAT-file with the same name as that of the script.
The fastest way possible is probably Matlab's save command. Alternatively, you could fwrite the whole matrix to a binary file.
Using dlmwrite
converts the values to text, which takes time and is more data to write to disk. Don't do that unless you really need to have the data in that format. Note that dlmwrite
will be faster if called one time with a big matrix instead of in a loop that incrementally writes your file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With