MATLAB Answers

will99
0

What is the best way to save data into a txt file

Asked by will99
on 21 Mar 2019
Latest activity Commented on by will99
on 22 Mar 2019
I have these data in a matrix and I want to save them into a txt file
but I got diffrenet values than what in my matrix it was something like this (in that format)
4.6998106645411053e+02
I used save fuction to try and save my data I want to save is there another way to save data into txt file?
save('new doc.txt','M','-ascii','-double','-tabs') % M is the matrix
type('new doc.txt')
6540601141.61867 13577823444.2938 28101317825.1798
7569519373.48601 15264346993.3944 30754547025.5567
7387340146.18493 15158865708.5425 31019062144.9410
6251317371.90850 12958424682.6582 26803084252.4354
6734644847.83862 13687649437.8130 27810201085.8812
6849537690.44554 14134553528.2659 29089340966.3231
7385568328.07828 15044694671.3799 30591374573.0212
6381280737.62946 12989993198.7250 26448459532.9256

  3 Comments

dpb
on 21 Mar 2019
Show us what
disp M
gives for the same M. I've never seen save not write the correct data; I'd be willing to bet that is what was in M.
There are any number of ways to write text files; if you have need for a given format, then fprintf is your basic choice; the other, simpler ways make assumptions about precision and format to save you the trouble.
I was trying to save it in txt file is fprintf the best way for txt format?

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by madhan ravi
on 22 Mar 2019
 Accepted Answer

If your using 2019a you may try the newly introduced writematrix().

  1 Comment

Thank you I have Matlab 2018b but I will update it and try the new function

Sign in to comment.