如何将uitable()保存为PDF,JPG等

问题描述 投票:1回答:1

如何将uitable()保存为PDF,JPG等?

使用Matlab R2018a,没有精美的附件。由于实际数据的大小/复杂性,正在寻找使用表而不是数组的解决方案。

    % construct simple table as example %
    t = array2table(zeros(4,1));
    t.Properties.VariableNames{'Var1'} = 'id';
    t.id(:) = 1;
    t.fieldA = {'a'; 'b'; 'c'; 'd'};
    t.GroupCount = [22; 1; 19; 0];

    f = uifigure;
    uit = uitable(f, 'Data', t);
    % what command to save to PDF? or JPG, PNG, whatever

请注意,f = figure不起作用,否则将很容易另存为PDF(我不确定通过表t时遇到问题,我不确定):

f = figure; 
uit = uitable(f, 'Data', t);

Error using uitable
Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App Designer.
matlab matlab-figure matlab-uitable
1个回答
1
投票

您可以将其创建为figure而不是figure进行保存。但是您不能将表传递给它。为此,您需要一个简单的数组或一个单元格数组。由于您具有混合数据类型,因此,单元数组是必经之路。使用uifigure将表转换为单元格数组。

uifigure

现在您可以以任何所需的格式将table2cell与您的图形一起使用。例如:

table2cell

结果:

f = figure; uit = uitable(f, 'Data', table2cell(t)); uit.ColumnName={t.Properties.VariableNames{:}}; %renaming columns to that of table uit.RowName=[]; %removing default row numbering as in your uitable

© www.soinside.com 2019 - 2024. All rights reserved.