convert numbers that contain the scientific notation e to the long format then round it to the fourth decimal?

22 visualizzazioni (ultimi 30 giorni)
Hello,
suppose that we have a matrix A (2*3) that contains the values:
A= [ 0.0037 0.0089 0.0057
0.0041 0.-3.000000000000000e-04 0.0034]
I need to make the elment A(2,2) to this form (-0.0003) , where A becomes:
A= [ 0.0037 0.0089 0.0057
0.0041 -0.0003 0.0034]
So, how can I do this?
Regards,

Risposte (1)

Guillaume
Guillaume il 21 Lug 2019
Modificato: Guillaume il 21 Lug 2019
I assume that what you mean is that you'd like matlab to display numbers as -0.0003 instead of 3e-4. If so,
format shortg
will change the display to avoid scientific notation as much as possible.
If instead you're saying you want to store -0.0003 instead of 3e-4,. that makes no sense, they're the same numbers (and are stored internally in a completely different format). Furthermore, due to the way numbers are stored on a computer, it's actually impossible to store -0.0003 exactly (in ieee754 representation such as double or single). The actual number that is stored in memory is actually -0.0002999999999999999737189393389513725196593441069126129150390625, the nearest representable number to -0.0003. Any program will round that to -0.0003 for display.

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by