Format Number (exponential notation)

조회 수: 61 (최근 30일)
Matteo Peruzzi
Matteo Peruzzi 2020년 3월 23일
댓글: Matteo Peruzzi 2020년 3월 23일
I have a code and a result is the variabile: T= 5.6789e-05
I want use a function for change the exponential notation from e-05 to e-6 and print the value in a graph.
Correct value T= 56.789e-06
Help me
sprintf('time T= %3.3e\n',T)

답변 (1개)

Walter Roberson
Walter Roberson 2020년 3월 23일
You will not be able to do this directly. sprintf and related do not offer any control over where the decimal is put.
You can use log10 to probe the power of 10 for the value, such as -5. Divide by that power minus 1 to get a value with two leading decimals. Format that. Add on sprintf('e%d') the power minus 1
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 3월 23일
X=5.6789e-05;
D=floor(log10(5.6789e-05))-1;
t2S = sprintf('time to half time t2=%.4fe%d', X/10^D, D) ;
and use the variable in constructing the legend.
Matteo Peruzzi
Matteo Peruzzi 2020년 3월 23일
I have change anything.....and work fine ;)
GOOD!!! Really thankyou
Now Italy is not a good place. 6000 dead in two weeks. Take care and rest at home.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by