How to get Exponent of Scientific Notation in Matlab

exponent, matlab, matrix, scientific-notation

Solution

Basic math can tell you that:

floor(log10(N))

The log base 10 of a number tells you approximately how many digits before the decimal are in that number.

For instance, `99987123459823754` is `9.998E+016`

`log10(99987123459823754)` is `16.9999441`, the floor of which is `16` - which can basically tell you "the exponent in scientific notation is 16, very close to being 17".

Floor always rounds down, so you don't need to worry about small exponents:

0.000000000003754 = 3.754E-012
log10(0.000000000003754) = -11.425
floor(log10(0.000000000003754)) = -12

Problem

When the numbers are really small, Matlab automatically shows them formatted in Scientific Notation. Example: ``` A = rand(3) / 10000000000000000; A = 1.0e-016 * 0.6340 0.1077 0.6477 0.3012 0.7984 0.0551 0.5830 0.8751 0.9386 ``` Is there some in-built function which returns the exponent? Something like: `getExponent(A) = -16`? I know this is sort of a stupid question, but I need to check hundreds of matrices and I can't seem to figure it out. Thank you for your help.

Original source