Поля таблиц в формате в генераторе отчетов PDF - Matlab - PullRequest
1 голос
/ 08 мая 2020

Когда я сохраняю таблицу в формате PDF (с помощью генератора отчетов), я не получаю поля numeri c (Index1, Index2, Index3) в формате shortG (всего 5 цифр). В чем проблема и как ее исправить?

Код:

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

1 Ответ

3 голосов
/ 08 мая 2020

Чтобы исправить это, перед записью в PDF отформатируйте массивы numeri c в массивы символов с 5 значащими цифрами.

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

Приведенное выше изменение дает следующий результат:

image


Edit:

To bring back the headers:

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 для извлечения имен переменных.

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

что дает:

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...