hi , i use the following statement ,

1 view (last 30 days)
fprintf('S=%d Z0 =%d PHI=%d MSEreal=%d MSEfuzzy=%d Numberofreal=%d Numberoffuzzy=%d\n', s,z0,phi,MSEreal,MSEfuzzy,numberreal,numberfuzzy);
for s=7 and z0=0.2 and phi=0.6 and so ,
the result show this values in terms of e . as following
S=7 Z0 =2.000000e-01 PHI=6.000000e-01 MSEreal=1.732151e-04 MSEfuzzy=1.070943e-04 Numberofreal=127 Numberoffuzzy=223
how to display result without e ?.

Accepted Answer

Massimo Zanetti
Massimo Zanetti on 28 Sep 2016
If you want to show decimal numbers just do this:
fprintf('S=%d Z0=%.1f PHI=%.1f MSEreal=%.1f MSEfuzzy=%.1f Numberofreal=%d Numberoffuzzy=%d\n', s,z0,phi,MSEreal,MSEfuzzy,numberreal,numberfuzzy);
  2 Comments
Walter Roberson
Walter Roberson on 28 Sep 2016
Right. The %d format is only for values that are integral. Logical values convert to integral and so can be printed using %d; characters convert to integral and so can have their numeric position printed using %d.
Complex values printed with %d will have their complex part discarded.
Any numeric value that (after discarding of any complex component) is not integral will be printed by %d format using scientific format.
If you have a value that is not integral and you wish to print it without scientific notation then your options are:
  • floor() or fix() or round() it so that it becomes integral, and continue to use %d format
  • use %.f or %.0f format to print it without any decimal place, even if it is a large number; the number will be rounded to the nearest integer
  • use %.Nf where N is a positive integer, to print with N decimal places after the period; the last decimal place printed will represent rounding
The %g format can also be useful for printing floating point numbers, but it will switch between integer (%d) and fixed point (%f) and exponential format depending on how well the number fits into the width (default: 5) specified.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!