How to keep scientific notation in string.

조회 수: 19 (최근 30일)
daniel adams
daniel adams 2021년 12월 14일
답변: Walter Roberson 2021년 12월 14일
I have some values in an array in matlab
epsilon=[1e-01,9e-02,8e-02]
I want to turn these values into a string so I can use them on plots etc.
stringepsilon=string(epsilon)
but the output is not in scientific format :
stringeps="0.1" "0.89" "0.08"
how do I make it appear in scientific format.

답변 (2개)

Awais Saeed
Awais Saeed 2021년 12월 14일
편집: Awais Saeed 2021년 12월 14일
epsilon=[1e-01,9e-02,8e-02];
% try num2str()
str1 = string(num2str(epsilon,'%.e '))
str1 = "1e-01 9e-02 8e-02"
% or try sprintf()
str2 = string(sprintf('%.e ',epsilon))
str2 = "1e-01 9e-02 8e-02 "
whos
Name Size Bytes Class Attributes epsilon 1x3 24 double str1 1x1 170 string str2 1x1 172 string
  댓글 수: 1
daniel adams
daniel adams 2021년 12월 14일
Yeh I dont really want size $1x1$ though?

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


Walter Roberson
Walter Roberson 2021년 12월 14일
epsilon=[1e-01,9e-02,8e-02];
compose("%.e", epsilon)
ans = 1×3 string array
"1e-01" "9e-02" "8e-02"

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by