The fastest way to save matlab matrices

I use Matlab to make an external call in C ++, and then I get a huge computed matrix. The matrix is ​​very huge, and I do not have access to this source code of a C ++ program. (if I have it, I will save it from C ++ right away)

Right now, on my system, this C ++ program uses only 1 second to calculate data and send it back to Matlab, and Matlab dlmwrite takes 200-300 seconds to save this single array to disk. I have a few thousand more to calculate, and I want to reduce the time.

So what is the fastest way to save in matlab?

+5
source share
2 answers

- , , Matlab save. , fwrite .

dlmwrite , . , . , dlmwrite , , , .

+5

Matlab, , , fwrite fprintf ASCII. , Matlab Java, IO, . -

Java Code
package mypackage.release;

import java.io.DataOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException


public class MatrixWriter {
  public static void write(String fileName, double[] matrix) throws IOException {
    DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
    for (double d : matrix)
      dos.writeDouble(d);
    dos.close();
  }
}

Matlab Code
import mypackage.release.MatrixWriter;
M = get matrix from c++;
MatrixWriter.write('myfile.dat', M(:));

- , . , .

+2

All Articles