writetable 関数で、数値をファイ​ル出力する際、各列の​数値桁数を任意に設定​できますか?

20 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 8 de Sept. de 2021
Respondida: MathWorks Support Team el 24 de Dic. de 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)
 

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 8 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!