transform exponential number to decimal
8 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
David Hill
2023 年 9 月 11 日
M1 = importdata("M1.mat");
A = compose('%d (%3.2f%%)', [M1(:,1), M1(:,2)])
0 件のコメント
その他の回答 (1 件)
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]
S = compose("%d (%3g%%)", M1)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!