필터 지우기
필터 지우기

transform exponential number to decimal

조회 수: 10 (최근 30일)
Alberto Acri
Alberto Acri 2023년 9월 11일
답변: Steven Lord 2023년 9월 11일
Hi. I have the following cell:
M1 = importdata("M1.mat");
A = compose('%d (%2d%%)', [M1(:,1), M1(:,2)]);
How can I turn exponential numbers (inside the brackets) into decimal numbers?

채택된 답변

David Hill
David Hill 2023년 9월 11일
M1 = importdata("M1.mat");
A = compose('%d (%3.2f%%)', [M1(:,1), M1(:,2)])
A = 5×1 cell array
{'81 (6.18%)' } {'82 (7.51%)' } {'83 (9.03%)' } {'84 (10.20%)'} {'85 (9.43%)' }

추가 답변 (1개)

Steven Lord
Steven Lord 2023년 9월 11일
Use a different format specifier. The second column of your data doesn't contain integer values, so using %d for that column is not the right thing to do. Let's try %g instead and specify that you want three significant figures. See the documentation for the formatSpec input argument to the compose function for more information about the different format specifiers you can use.
% Sample data
M1 = [81, 6.18; 82, 7.51; 83, 9.03; 84, 10.2]
M1 = 4×2
81.0000 6.1800 82.0000 7.5100 83.0000 9.0300 84.0000 10.2000
S = compose("%d (%3g%%)", M1)
S = 4×1 string array
"81 (6.18%)" "82 (7.51%)" "83 (9.03%)" "84 (10.2%)"
FYI while your result was stored in a cell array, I used double quotes in my call to the compose command to create a string array instead.

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by