problem printing double format values

61 次查看(过去 30 天)
ram m
ram m 2011-11-29
I am unable to print the values in double format, suppose if I have a value b=0.394944961213358 [1x1 double] it shows ??? Undefined function or method 'fprinf' for input arguments of type 'char'.
How can I round it to first four decimal values( as 0.3949) and print it to a file.
Thanks Ram
  1 个评论
ram m
ram m 2011-11-29
Sir I have one more question, I am trying to write the value of b for every loop to a file, but the it is updating the present value for next loop, How can I write the values in a column like a database
i=1
b =
i=2
b =
...
i = n
b=
Thanks

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2011-11-29
The function name is fprintf not fprinf
fprintf(fid, '%.4f', b)
  3 个评论
Walter Roberson
Walter Roberson 2011-11-29
In response to the Comment you added to your question:
%before the loop
fid = fopen('YourOutputFile.txt', 'wt');
%inside the loop
fprint(fid, 'i = %d\nb = %.4f\n', i, b);
%after the loop
fclose(fid);

请先登录,再进行评论。


Honglei Chen
Honglei Chen 2011-11-29
You missed a t, it's fprintf, not fprinf

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by