如何将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.
您可以将其创建为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