I have a large array with numbers like these:
3.2692e+17
However, I want to extraxt the first three numbers, as I am interested in the 32.6 (or 32.7 if rounded). Some numbers are 3.2692e+16 for example, so dividing by e+16 is not working. What is the easiest way to do this?

댓글 수: 1

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 10일
편집: KALYAN ACHARJYA 2019년 5월 10일
Input=3.2692e+17
Disired Result=32.6
You want convert or extract?

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

 채택된 답변

Star Strider
Star Strider 2019년 5월 10일

0 개 추천

One approach:
f = @(x) round(x.*10.^floor(1-log10(abs(x))),2);
producing:
x = [3.2692e+17; 3.2692e+16; 4.2516E+8];
Result = f(x)
Result =
3.27
3.27
4.25
Change the last argument to the round function to change the number of decimal places the function returns.

댓글 수: 2

Lieke Numan
Lieke Numan 2019년 5월 10일
Thanks a lot!
Star Strider
Star Strider 2019년 5월 10일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2019년 5월 10일

댓글:

2019년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by