0

I have this big ( 40000 x 40000 ) sparse matrix in matlab workspace and I need to do some statistical test on each element (also the zeros) of it. Since this is pretty slow on matlab, I decided to solve the problem using a simple c++ code. I know how to do what I need to do once I have a c++ array that "stores" the matrix.

The problem is that I do not actually know how to menage to move the matrix from matlab to c++. I thought that I could write the full matrix in a txt or csv file and read it in c++ but I don't know how to write a c++ function/script that can read a csv/txt file and store the elements it reads as an array.

Can you please help me out? Also other possible approaches are more to welcome.

  • there are dozens of tutorials and question on SO about reading data from a file. Take a look e.g. here http://stackoverflow.com/questions/26979236/reading-integers-from-file-and-store-them-in-array-c – 463035818_is_not_an_ai Jan 17 '17 at 14:14
  • 1
    I'm not sure that saving it an external file, parsing it, and then processing it in C++ is going to be any faster. If you tell us what your'e trying to do, we may be able to offer a decent MATLAB solution – Suever Jan 17 '17 at 14:14
  • Another one [here](http://stackoverflow.com/a/19602428/1460794). – wally Jan 17 '17 at 14:14
  • I process full matrices of 5B data points quite fast in MATLAB. If you have a truly sparse matrix with 1.6e9 elements, that should be no problem at all for MATLAB, [as it's optimised to deal with matrix calculations](http://stackoverflow.com/questions/6058139/why-is-matlab-so-fast-in-matrix-multiplication). – Adriaan Jan 17 '17 at 14:18
  • Basically I need to calculate an hypergeometric cdf that has several parameters, one of them is specified by each single entry of the 40000 x 40000 matrix and the others are obtain by summing specific values among rows and columns. So basically I need to make a giant loop for i=1:16*10^8. That is why I thought that it could be kind of slow in matlab. – Ninja Warrior Jan 17 '17 at 14:54

0 Answers0