How can I display a MATLAB table in a figure?
903 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2015-11-13
编辑: MathWorks Support Team
2021-3-5
I have a MATLAB table where each of the variables contains a single column of data. How can I display the table in a figure?
采纳的回答
MathWorks Support Team
2021-3-5
编辑:MathWorks Support Team
2021-3-5
You can either use "uitable" or a more complicated series of commands depending on how you want the table to look.
For example, let us assume you have a table defined by the following code:
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
T = table(Age,Height,Weight,'RowNames',LastName);
1.) If you want the table to have adjustable-width columns and a more stylized look, execute the following "uitable" command to display the table "T" in a figure:
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0, 0, 1, 1]);
You can refer to the following documentation link for more information on "uitable":
2.) If you want the table to look very similar to how it looks when outputted in the MATLAB command window, execute the following series of commands to display the table "T" in a figure:
% Get the table in string form.
TString = evalc('disp(T)');
% Use TeX Markup for bold formatting and underscores.
TString = strrep(TString,'<strong>','\bf');
TString = strrep(TString,'</strong>','\rm');
TString = strrep(TString,'_','\_');
% Get a fixed-width font.
FixedWidth = get(0,'FixedWidthFontName');
% Output the table using the annotation command.
annotation(gcf,'Textbox','String',TString,'Interpreter','Tex',...
'FontName',FixedWidth,'Units','Normalized','Position',[0 0 1 1]);
You may find the following documentation links useful:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!