Problem about Output in a txt file?How to solve it

1 visualización (últimos 30 días)
tabw
tabw el 13 de Sept. de 2014
Editada: Rick Rosson el 13 de Sept. de 2014
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)

Respuesta aceptada

Rick Rosson
Rick Rosson el 13 de Sept. de 2014
Editada: Rick Rosson el 13 de Sept. de 2014
Open the file with permission set to append:
fileID = fopen('exp.txt','a');

Más respuestas (0)

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by