MATLAB: Change of expontial precision

exponentialexponential notationprecision

Hi, i wanted to know if there is any way to precise the exponential number in fprintf or sprintf. I have data like 4.123E+02, and i want to print it like 4.123E+2. Is there a possible assignment for that?

Best Answer

I wrote a little utility program a while ago to do just that (for use in text object strings):
Q1 = 4.123E2;
expstr = @(x) [x*10.^floor(1-log10(abs(x))) floor(log10(abs(x)))];
Result = sprintf('%.3fE%+d', expstr(Q1))
Result =
'4.123E+2'
The output is a character array.