Floating Number without "e"?

35 次查看(过去 30 天)
Hello everyone!
I'm a begginer in Matlab struggling to plot a graph. I'm having a hard difficult with my decimal numbers, because I have a very small one. My program is returning like "2.917974892076614e-04" and I didn't want this notation. I need the normal number, even if it is rounded - no problem!
Well, can I round the number to the maximum value acceptable by the var type? Or can I stop my program from writing like this and make it return the original number?

采纳的回答

Walter Roberson
Walter Roberson 2018-5-19
If you are using R2015b or later, do not bother trying to work with format or vpa() for this purpose. Instead, use
ax = gca;
ax.XRuler.TickLabelFormat = '%.5f';
or the same with YRuler .
R2015a had a similar facility but the name XRuler and YRuler were different in that one release.
For earlier releases, set the axis XTickLabel or YTickLabel properties as appropriate. For example,
xt = get(gca, 'XTick');
xlab = cellstr( num2str(xt(:), '%.5f') );
set(gca, 'XTickLabel', xlab)
When you work with XTickLabel or YTickLabel then if you zoom or pan then the labels are not automatically recreated in appropriate format to match new appropriate new ticks. When you work with the newer TickLabelFormat, then any new tick brought into view by zoom or pan will be automatically formatted properly.
  2 个评论
giovanacgois
giovanacgois 2018-5-19
I'm really gratefull for your answer! Thanks for your kindneess!!! You helped me so much.
Walter Roberson
Walter Roberson 2018-5-19
Go to Preferences -> Variables and change "Default array format" to "long g". Now look at the data again.
The representation of the data as being in floating point format in the Variable Browser has absolutely no effect on graphics.

请先登录,再进行评论。

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2018-5-19
编辑:Ameer Hamza 2018-5-19
If you want to calculate or display very small or very large numbers without using e notation then use vpa
digits(20) % set how many digits to use after the decimal point
vpa(0.0000537523327672541)
ans =
0.000053752332767254096626
Also as you can see that there is a little difference between value inside vpa() and the number displayed by the MATLAB. That is because of finite precision of floating point numbers in MATLAB. The detailed discussion and the method to avoid this can be found here.
  2 个评论
giovanacgois
giovanacgois 2018-5-19
I came close to solving with your help. But if I need to do operations with these numbers, how can I convert them back to double, considering the decimal places?
Example:
I want a number like: 1.1234, right?
So I have: x=5.3752e-05 to convert.
K>> digits (20)
K>> vpa(x)
ans =
0.000053752000000000003065
It's right, but I want just "0.0001". I tried:
K>> digits(4)
K>> vpa(x)
ans =
5.375e-5
It still returns e.
Ameer Hamza
Ameer Hamza 2018-5-19
Why do you want "0.0001" your actual number is 0.00005..., If you want to round the number then use
vpa(round(x,4))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by