write multiprecision binary file with matlab -
I would like to write a table with 1 integer, after which there will be 3 pairs of binary formats. Of course I can only do this for loop
for i = 1: sz fwrite (fid, integ (i), 'int'); Filitt (fade, double (i, :), 'double'); End
but it is very slow for arrays with a few million entries, maliciously I should keep this [int32 float64 float64 float64] format because it was used by a program The file format specification is because it is the most effective way for a handle (without writing an .mex)?
edit: Respect the order and type of variable nx3 double >> to convert an array of
(2xn) x3 int32
, then to write everything at once, arrays Rebuild and add.
outfile4 = 'test1.bin'; Tic4 = Tic; % // Everything reshape table 2write = int32 (zero (2 * nCol + 1, nPt);); Write table 2 (1, :) = integ. '; % 'For k = 1: nCol ixLine = (k-1) * 2 + 2; Table2write (ixLine: ixLine + 1, :) = reshape (double (((,, k, '' int 32 ''), 2, []); end =% write fid = fopen (outfile4, 'w') ; Count = fwrite (fid, table2write, 'int32'); Falcos (fade); Elapsed4 = toc (tic4)
As a result:
elapsed4 = 0.794346687070910
Basic Answer:
If you can reconstruct your file, you can earn a lot of time.
Consider the following example:
outfile1 = 'E: \ TEMP \ Z_ToDelete \ Test1.bin'; Outfile2 = 'E: \ TEMP \ Z_ToDelete \ test2 Write 'to file with bin'; NPT = 0.5A6; Integ = int32 (RANDI (32000, NPT, 1); double = RAND (NPT, 3); %% // mixed precision tic1 = TIC; FID = Fopen (for outfile1, 'w'); k = 1: nPt fwrite (fid, integ (k), 'int'); filitt (fade, double (k, :), 'double'); End fclose (fid); Type elapsed1 = toc (tic1) %% // indexed to tic2 = tic; Fid = fopen (outfile2, 'w'); Filitt (fidd, integ, 'int'); Filitt (fidd, double, 'double'); FECLOS (FED); Elapsed2 = toc (tic2)
On my system, this output:
elapsed1 = 19.7780466501241 elapsed2 = 0.0309073378234669
Then handle Mattelb's writing of your full array, at a time, to write an exact line, it is much more efficient to specify from the line.
Negativity The reading of the same record from your saved file can be a bit more complex, but you can easily write a function that integer Will go to read, leave the rest of them, then read 3x
the doubles
.
If you can not actually give your data to multiplex / demtriplex, then consider changing your int
to double
You can write and full array:
tic3 = tic; A = [double (double) double; Fid = fopen (outfile2, 'w'); Filitt (fed, a, 'double'); FECLOS (FED); It is still much faster than the initial "mixed precision" solution elapsed3 = 0.483094789081886
When you've spent writing composite precision values, The only negative effect of this method will take less time to convert to the file size is a slight increase (~ 14%).
Comments
Post a Comment