writetable 関数で、数値をファイル出力する際、各列の数値桁数を任意に設定できますか?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 8 Sep. 2021
Beantwortet: MathWorks Support Team
am 24 Dez. 2021
writetable 関数で、数値をファイル出力する際、各列の数値桁数を任意に設定する方法を教えてください。
例えば、下記 table データにおいて、A 列は、下 1 桁、B 列は 下 3 桁、のように設定したいです。
>> data = [(1:3)', rand(3,1)];
>> T = array2table(data,'VariableName',{'A','B'})
T =
A B
_ _______
1 0.81472
2 0.90579
3 0.12699
>> writetable(T,'mydata.csv','WriteRowNames',true)
Akzeptierte Antwort
MathWorks Support Team
am 8 Sep. 2021
writetable 関数では、数値データは long g 形式で出力され、任意の桁数で出力することはできません。
代替案として、num2str関数などで、数値を任意桁数の文字列に変換する方法があります。
>> T.A = num2str(T.A,'%1.1f\n');
>> T.B = num2str(T.B,'%1.3f\n');
>> T
T =
A B
___ _____
1.0 0.815
2.0 0.906
3.0 0.127
>> writetable(T,'mydata.csv','WriteRowNames',true)
>> type mydata.csv
A,B
1.0,0.815
2.0,0.906
3.0,0.127
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!