# Export matrices from time depended CFD calculation?

Posted 8 months ago
741 Views
|
|
0 Total Likes
|
 Hello, I am doing a 2D CFD calculation using my own code (not NDSolve) and I would like to find the most efficient way of exporting the results for every time step. For that I created a toy problem a = RandomReal[{-10, 10}, {600, 600}]; AbsoluteTiming[ Export[NotebookDirectory[] <> "/d.mat", a]; ] This is the fastest one I found but it has two problems. First, it requires MATLAB and the second is even in MATLAB I don't have the direct access to the a matrix, i.e., I have to do the following. vxm=load('a.mat'); a=vxm.Expression1; If I export as .txt I have problems with { shown in the figure below or if I try MatrixFormat[a] and export as .txt. I have the following problem. On top of everything, .mat takes 0.15 seconds and .txt takes 0.8 seconds (.csv takes 7 seconds) . Imagine I had to write to a file maybe 100000 times. That is a lot of seconds :) . Any advice to make exporting fast and generic?
 I suggest that you read on BinaryWrite and BinaryReadList functions. For a random matrix of the same size you used in the example it takes 0.005651` seconds to store it with 32 bits for each real number (i.e., single precision). It approximately takes twice this time to store it with 64 bits for each real number (i.e., double precision). I work with SSD, but it is approximately 15 times faster than storing it to a .mat file. The one thing you have to notice is that when you store a matrix, it is flattened out and you need to partition it again after reading, but this is negligible timeOne additional comment - you can import .mat files with Mathematica. No need for Matlab for this operation...yehuda