In Matlab how to use variables for the numbers in scientific notation (matissa and exponent)?

Vass picture Vass · Mar 11, 2012 · Viewed 25.9k times · Source

I am using Matlab and using numbers in scientific notation, which are represented with the letter e for the exponent. An example in Matlab:

>> 2e5
ans =
200000

Now would like to work with numbers in scientific notation, but using variables to hold the values of the mantissa and the exponent (left and right side of the e respectively). I do not understand how this can be done without the variable names merging with the letter e for the exponent. Eg:

>> rr=5;
>> 2err
??? 2err
|
Error: Unexpected MATLAB operator.

Can this still be done? Or must I use the manual approach:

>> 2*10^rr
ans =
200000

Answer

Sam Roberts picture Sam Roberts · Mar 12, 2012

You must use the manual approach; you can't use scientific notation like that with variables. You might want to use 2.*10.^rr, with the ., to enable you to use the same statement with arrays of numbers.