フィルターのクリア

write to file in exponential notation

15 ビュー (過去 30 日間)
Maider Marin
Maider Marin 2011 年 4 月 2 日
Iam writing a variable r to file using the following code
r= [0.000452403093670532 0.000445718222208873];
str='test.txt';
str1=['r =',mat2str(r)];
dlmwrite(str,str1,'-append', 'delimiter', '', 'precision','%-6.6e','newline', 'pc');
but no matter how I try always write it in decimal notation. I want to write it in exponential notation somenthing like
r= [4.524e-4 4.457e-4];
any help will be grately appreciated!!

回答 (3 件)

Matt Fig
Matt Fig 2011 年 4 月 2 日
Try FPRINTF instead of DLMWRITE.
  1 件のコメント
Maider Marin
Maider Marin 2011 年 4 月 3 日
I try this one but the formating was not easy, since I need in the file
r=[ 1st value 2nd value] and then I got r=[ 1st value r=[ 2nd value I guest I could work it out but I did not see it right away

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


bym
bym 2011 年 4 月 2 日
how about
strl = sprintf('r = %5.4e %5.4e ',r)
  1 件のコメント
Maider Marin
Maider Marin 2011 年 4 月 3 日
The problem is that the real r has 2400 entries, and I do not think I can do that with this

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


Maider Marin
Maider Marin 2011 年 4 月 3 日
Iam writing a variable r to file using the following code
r= [0.000452403093670532 0.000445718222208873];
str='test.txt';
str1=['r =',mat2str(r)];
dlmwrite(str,str1,'-append', 'delimiter', '', 'precision','%-6.6e','newline', 'pc');
I think I figure it out. The problem is with mat2str(r) I am not specifiying format, so it takes the original format and when I use dlmwrite that format does not work because it is already a string. I redo the code I got something like
r= [0.000452403093670532 0.000445718222208873];
str='test.txt';
str1=['r =',num2str(r,'%6.3e\t\t')];
dlmwrite(str,str1,'-append', 'delimiter', '','newline', 'pc');
Thanks for your answers

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by