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

StackOverflow https://stackoverflow.com//questions/9655668

  •  11-12-2019
  •  | 
  •  

Question

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
Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top