MATLAB: Convert any decimal number between 1 to 10 by multiplying the number with 10^n.

mathematicsMATLAB

I have to convert any decimal number between 1 to 10 by multiplying the number with 10^n. As for example, if a=12.345 it should be 1.2345*10^1 if a=2.345 it should be 9.2345*10^0 if a=0.345 it should be 0.345*10^1 if a=0.0345 it should be 3.45*10^2 How can i do that ?

Best Answer

I wrote a little utility function for my own use a while back to do just that:
expstr = @(x) [x*10.^floor(1-log10(abs(x))) floor(log10(abs(x)))];
a = 12.345;
b = expstr(a)
b =
1.2345 1.0000
I leave the rest to you.
Related Question