How to save matrix to .dat file in standard notation

38 ビュー (過去 30 日間)
Dipie11
Dipie11 2019 年 4 月 22 日
コメント済み: Dipie11 2019 年 4 月 22 日
Hi!
I would like to save a binary matrix 'A' to the file 'output.dat' without scientific notation formatting. For instance the matrix A has the (1,1) element, A(1,1) = 0. But it is saved as 0.0000000..e+00, when I'd simply like to to be saved as just 0.
I'm currently using the following basic save function,
A = [0 1 1 0; 0 0 0 1; 1 0 1 0; 0 0 0 0] % Example binary matrix A
save(['output=' num2str(i+1) '.dat'],'A','-ascii');
any help would be greatly appreciated.
Thank you!

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 22 日
You cannot do that using save -ascii: save -ascii uses a fixed format.
Probably the easest way is
filename = sprintf('output=%d.dat', i+1);
dlmwrite(filename, A, ' ' )
  1 件のコメント
Dipie11
Dipie11 2019 年 4 月 22 日
Awesome, thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by