【问题标题】:Formatting table display in MatlabMatlab中的格式化表格显示
【发布时间】:2017-07-28 22:11:16
【问题描述】:

我有一个table,其中包含不同类型的列。我正在使用函数writetable(...) 将其导出到excel。然而,我想知道如何以不同的格式显示一些列。

例如以 % 为单位的格式四舍五入为 2 个整数。例如。 0.025 --> 2.5%.

T = table;
T.('Test') = rand(100,1,1);

【问题讨论】:

    标签: matlab matlab-table


    【解决方案1】:

    最简单的方法是,如果它在您的表格中采用这种格式。您也可以通过 Matlab 打开 excel 并在其中以编程方式对其进行格式化,但这会比较麻烦。

    t = array2table(rand(3))
    t.(3) = cellstr(num2str(t.(3)*100, '%4.2f%%'))
    writetable(t, 'test.csv')
    

    t =

     Var1        Var2       Var3  
    _______    ________    _______
    
    0.73634     0.70405    0.33086
    0.39471     0.44231    0.42431
    0.68342    0.019578    0.27027
    

    t =

     Var1        Var2        Var3  
    _______    ________    ________
    
    0.73634     0.70405    '33.09%'
    0.39471     0.44231    '42.43%'
    0.68342    0.019578    '27.03%'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-04
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多