dlmwrite alternatives when the matrix size is large

3 views (last 30 days)
I have a matrix(point cloud) of size 379422x3 and it takes around 20 secs to write it to a text file. I'm looking for quicker ways of writing this data to a text file. Any suggestions
  1 Comment
Dara Parsavand
Dara Parsavand on 26 Jun 2019
I have run into this before but forgot that fprintf is much much faster. In my case I wanted to write out a 240e6x1 and I got tired of waiting after 20 minutes. fprintf finished before I realised (a few minutes at the most).
In your case, I just ran:
tic
M = rand(379422,3);
fid = fopen('test.txt','w');
fprintf(fid, '%d, %d, %d\n', M(:, 1), M(:, 2), M(:, 3));
fclose(fid);
toc
which finished in 0.63 sec
You can modify the format line (using tabs over comma). There is surely another way to do this that dosn't involve hardcoding the number of columns but it works and in my case I only needed one column.

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!