I have two big matrices in two files, A (21,000 x 80,000) and B(3,000 x 80,000) that I want to multiply:
C = A*B_transposed
Currently I have the following script:
A = dlmread('fileA')
B = dlmread('fileB')
C = A*(B')
dlmwrite('result', C)
exit
However, reading the matrices (first two lines) takes very long and Matlab (after each dlmread) proceeds to print these matrices. Do you know how to disable this printing and make the process faster?
To suppress printing you merely need to put a semicolon after each line:
One way to speed up the read is to tell Matlab what delimiter you are using, so that it doesn’t need to be inferred. For example, if the file is tab delimited you could use
or if it’s comma delimited you could use:
Other than that, you could consider using a different file format. Where are the files generated? If they’re generated by another Matlab process, then you could save them in Matlab’s binary format, which is accessed using
loadandsave:For a quick benchmark, I wrote the following matrix to two files:
I then ran two benchmarks:
Here the version using
loadcame in at half the time of thedlmreadversion. You could do your own benchmarking for matrices of the appropriate size and see what works best for you.