How to save data in a text file in a specific format?

I want to save the matrix to a text file, so I can read it with another program. Now I am using:

save('output.txt', 'A','-ascii');

But this saves my file as

6.7206983e+000  2.5896414e-001
6.5710723e+000  4.9800797e-00
6.3466334e+000  6.9721116e-001
5.9975062e+000  1.3346614e+000
6.0224439e+000  1.8127490e+000
6.3466334e+000  2.0517928e+000
6.3965087e+000  1.9721116e+000

But I would like them to be saved without "electronic notation", and not with all the numbers. Is there an easy way to do this?

Edit: Thanks! This works great. Sorry, but I think I messed up your editing with a rollback.

+3
source share
2 answers

I would use a function fprintfthat allows you to determine which format will output the data. for example

fid = fopen('output.txt', 'wt');
fprintf(fid,'%0.6f %0.6f\n', A.');
fclose(fid);

A . , fopen fclose.

+10

Doto gnovice, .

dlmwrite (, ) . . , dlmwrite - 5-10x , fopen/fprintf/fclose. (edit: , 15x10000)

+3

Source: https://habr.com/ru/post/1709396/


All Articles