Round saved variables (not command line output) to 5 decimal places

12 visualizaciones (últimos 30 días)
I am trying to create a series starting at 0.00625 km, with a step of 0.00625 km i.e. the first three terms would be: 0.00625 0.0125 0.01875 .... I am creating this series using:
dx=0.00625;
xstart=0.00625;
xend=35;
vbx=(xstart:dx:xend);
However the variable vbx is only saving to 4 decimal place precision i.e. 0.0063 0.0125 0.0188 ...
I need the actual variable that is saved to have the correct precision - the output on the command line is not important.
Could someone tell me how to go about this?
round does not work unfortunately, I think that this is an error due to the class of the numbers?

Respuesta aceptada

Stephen23
Stephen23 el 22 de Abr. de 2016
Editada: Stephen23 el 22 de Abr. de 2016
MATLAB has not eaten your digits, you just need to change the format to display them:
>> vbx(1:5) % default format == short
ans =
0.0063 0.0125 0.0188 0.0250 0.0313
>> format longg
>> vbx(1:5)
ans =
0.00625 0.0125 0.01875 0.025 0.03125
Note that if you are using save then its precision is controlled by an optional input argument, and not the command window format.
  2 comentarios
K G
K G el 22 de Abr. de 2016
Thanks for this. If you are looking at variables by double clicking on them from the Workspace (as I do) it doesn't show you the full number unless you click into a cell. Which I have now just realised and was causing the confusion! Cheers.
Walter Roberson
Walter Roberson el 23 de Abr. de 2016
There is a preference that controls the format used by the browser

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 22 de Abr. de 2016

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by