PDF报告生成器中格式的表格字段-Matlab [英] Table fields in format in PDF report generator - Matlab

查看:257
本文介绍了PDF报告生成器中格式的表格字段-Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将表格另存为PDF(使用报告生成器)时,我没有得到shortG格式的数字字段(Index1,Index2,Index3)(总共5位数字).有什么问题,我该如何解决?

When I save a table as PDF (using report generator) I do not get the numeric fields (Index1, Index2, Index3) shortG format (total of 5 digits). What is the problem and how can I fix it?

代码:

function ButtonPushed(app, event)
        import mlreportgen.dom.*;
        import mlreportgen.report.*

        format shortG;
        ID = [1;2;3;4;5];
        Name = {'San';'John';'Lee';'Boo';'Jay'};
        Index1 = [71.1252;69.2343245;64.345345;67.345322;64.235235];
        Index2 = [176.23423;163.123423654;131.45364572;133.5789435;119.63575647];
        Index3 = [176.234;16.123423654;31.45364572;33.5789435;11.6647];
        mt = table(ID,Name,Index1,Index2,Index3);


        d = Document('myPDF','pdf');
        d.OutputPath = ['E:/','temp'];

        append(d,'Table 1: '); 
        append(d,mt); 
        close(d);
        rptview(d.OutputPath); 
end

推荐答案

要解决此问题,请在写入PDF之前将数字数组格式化为具有5个有效数字的字符数组.

To fix it, format your numeric arrays to character arrays with 5 significant digits before writing to PDF.

mt = table(ID,Name,f(Index1),f(Index2),f(Index3));

哪里

function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting. 
%at each tab. categorical is needed to remove ' 's that appear around char 
%in the output PDF file with newer MATLAB versions
%e.g. with R2018a, there are no ' ' in the output file but ' ' appears with R2020a
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (<undefined>) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end

以上更改给出了以下结果:

The above change gives the following result:

带回标题:

mt.Properties.VariableNames(3:end) = {'Index1', 'Index2', 'Index3'};

或以更通用的方式提取变量名而不是对其进行硬编码,可以使用

or in a more general way to extract the variable names instead of hardcoding them, you can use inputnames to extract the variable names.

V = @(x) inputname(1);
mt.Properties.VariableNames(3:end) = {V(Index1), V(Index2), V(Index3)};

给出:

这篇关于PDF报告生成器中格式的表格字段-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆