how to get decimal answers?

7 次查看(过去 30 天)
i have been using a for loop but the result comes in long digits of fraction?
i want to have the result in decimal. how can i avoid fraction answers?
  1 个评论
dpb
dpb 2022-8-6
format short, format compact
may suit.
If not, see format as to the options at comand line for echo'ed output.
If you want/need a specific output, then you'll have to format/write it yourself.
Show us code/and what you're getting that you don't like; we can't see your terminal from here...

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2022-8-6
If you are using the Symbolic Math Toolbox, use the double function if the expressions do not contain symbolic variables. If they do contain symbolic variables, numeric values must be supplied for them first, using the subs function. (The vpa function will also provide strictly numeric results, however the result will still be a symbolic variable.)

更多回答(1 个)

Walter Roberson
Walter Roberson 2022-8-7
sympref('FloatingPointOutput',true);
I personally do not recommend this approach, as I find that there are many cases where the symbolic form is more informative.

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by