MATLAB Answers

b=fprintf how to

12 views (last 30 days)
Opariuc Andrei
Opariuc Andrei on 30 Oct 2020 at 0:43
Commented: Star Strider on 30 Oct 2020 at 1:23
a=2.65987 ,after using the fprintf('%0.5g\n',a) i get the value i want being 2.6599 i tried doing b=fprintf('%0.5g\n',a) (i wanted to keep a better track of my work ) but it modified my result into 7 ,is there a way of keeping the b=fprintf('%0.5g\n',a) and still keeping the initial value 2.6599 ?

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 30 Oct 2020 at 0:58
If you want to store the result as ‘b’, use the related function sprintf:
b=sprintf('%0.5g\n',a)
It is a separate line of code, however you get to retain the result.

  2 Comments

Opariuc Andrei
Opariuc Andrei on 30 Oct 2020 at 1:05
thank you :)
Star Strider
Star Strider on 30 Oct 2020 at 1:23
As always, my pleasure!
In your original fprintf call, ‘b’ was the number of bytes fprintf wrote. See Get Number of Bytes Written to File for an detailed explanation.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!

Translated by