Problem about Output in a txt file?How to solve it
1 view (last 30 days)
Show older comments
x = 0:.1:1;
A = [x; exp(x)];
fileID = fopen('exp.txt','w');
fprintf(fileID,'%6s %12s\n','x','exp(x)');
fprintf(fileID,'%6.2f %12.8f\n',A);
fclose(fileID);
x exp(x)
0.00 1.00000000
0.10 1.10517092
0.20 1.22140276
0.30 1.34985881
0.40 1.49182470
0.50 1.64872127
0.60 1.82211880
0.70 2.01375271
0.80 2.22554093
0.90 2.45960311
1.00 2.71828183
Can I add data and output it row by row? like
x exp(x)
0 1
then I could add one more row without to define the x again?
x exp(x)
0 1
0.4 1.49
it is because the result inside a for loop each time only output one row.
But,I don't want store all the result into matrix ,then like what I do above.
I want each time after 1 loop it can add one row.
like writing stuff in csv file result(1,i) result(1,i+1)
0 Comments
Accepted Answer
Rick Rosson
on 13 Sep 2014
Edited: Rick Rosson
on 13 Sep 2014
Open the file with permission set to append:
fileID = fopen('exp.txt','a');
0 Comments
More Answers (0)
See Also
Categories
Find more on Import, Export, and Conversion 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!