Reading writing matrices in matlab

1 view (last 30 days)
Bob
Bob on 22 Apr 2014
Commented: Ken Atwell on 22 Apr 2014
I have a 160000 x4 matrix generated on matlab. To write it onto a .txt file using dlmwrite takes forever, maybe around 8-12 hours. Is there any function which does this writing efficiently? I can save it however as .mat file, but can matlab .mat files be referred to in C/C++ codes and can we use the efficient writing techniques from there?

Answers (1)

Image Analyst
Image Analyst on 22 Apr 2014
Why can't you just write it out in binary with fwrite()?
  4 Comments
Bob
Bob on 22 Apr 2014
Hi, I tried these lines
sym a b c d
Mat=[a b;c d]
>> FID = fopen('newfile.txt', 'wt');
>> fwrite(FID,sym2poly(Mat))
>> fclose(FID);
And the output is a set of randome characters in the newfile.txt
Ken Atwell
Ken Atwell on 22 Apr 2014
Well, not random. This is binary output suitable for reading in C with fread. The size of the file should be exactly 160000x4x8 bytes in size.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!