Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8687189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:03:27+00:00 2026-06-12T23:03:27+00:00

I have a large matrix (2e6 x 3) which I have to write to

  • 0

I have a large matrix (2e6 x 3) which I have to write to a text file.

dlmwrite takes about 230s to achieve this task.

From your experience what is the fastest way to write a large matrix to a text file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:03:28+00:00Added an answer on June 12, 2026 at 11:03 pm

    The following applies to MATLAB, but I suggest you try it in Octave. First of all, if you can – transpose the matrix. Here are examples using fprintf and csvwrite (essentially dlmwrite)

    A = rand(3, 1e6);
    tic;
    fid = fopen('data.txt', 'w+');
    for i=1:size(A, 1)
        fprintf(fid, '%f ', A(i,:));
        fprintf(fid, '\n');
    end
    fclose(fid);
    toc
    
    tic;
    csvwrite('data.txt', A);
    toc;
    
    Elapsed time is 1.311512 seconds.
    Elapsed time is 2.487737 seconds.
    

    If not transposed, it will take ages indeed. By default, fprintf flushes the buffer after every call. You can try to use W instead of w to open the file, but it does not improve the situation here too much.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large matrix from which I would like to gather a collection
Hi I have been working on a large matrix which displays the results of
I have a large correlation matrix result in R - for now about 30
I have a very large matrix(10x55678) in numpy matrix format. the rows of this
I have a large 3D matrix and a small 3D matrix which I want
I have a Java program which will produce a large matrix, at the end
I have a large matrix from which I would like to randomly extract a
I have a rather large, dynamic sparse matrix object class to write, and I
I have a large sparse matrix stored in Compressed Row Storage (CRS) format. This
I have a large matrix of 0 s and 1 s, that is mostly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.