matlab app designer: 表格table中的内容居中显示

本文介绍了如何在MATLAB App Designer中实现表格内容和列名的居中显示。通过添加特定代码,可以设置表格内容居中,并通过转换表格数据格式,实现列名同样居中。虽然MATLAB官方没有直接提供列名居中功能,但通过删除列名并将其作为表的一行数据,可以达到类似效果。
摘要由CSDN通过智能技术生成

matlab app designer: 表格table中的内容居中显示

在app designer中,表格内容默认居右显示(如下所示),并且没有可以更改为其它显示方式的按钮,该文给出了一种居中显示的方法。
在这里插入图片描述

  • 在填写表格内容的程序之后,加上如下代码,效果如图:
s = uistyle('HorizontalAlignment','center');
addStyle(app.UITable,s,'table','');

在这里插入图片描述

注:
怎么能把列的名称也同样居中?
没有很好的方法(不是我说的,matlab工程师的观点),不过非要实现的话,可以出歪招:删掉列名称,把列名称作为表的一行。具体例子,可以参考下面程序:

% T: your initial data stored in a table
T = array2table(rand(5,3),'VariableNames',["Lancaster","Cincinnati","Sofia"]);

% 1. Convert table to cell, move header names into row 1.
C = [T.Properties.VariableNames; table2cell(T)];

% Create two uitables for comparison
uifig = uifigure(); 
uifig.Position(3:4) = [ 679   420]; 
uitTable = uitable(uifig,'data',T,'Units','Normalize','Position',[.05 .05 .4 .8]);
uitCell = uitable(uifig,'data',C,'ColumnName',{},'RowName',{},'Units','Normalize','Position',[.55 .05 .4 .8]);
% Switch order of shaded rows
uitCell.BackgroundColor = flipud(uitCell.BackgroundColor);

% Center all cells of the table & bolden the first row
uisCenter = uistyle('HorizontalAlignment', 'center'); 
uisBold = uistyle('FontWeight','bold'); 
addStyle(uitTable, uisCenter)
addStyle(uitCell, uisCenter)
addStyle(uitCell, uisBold, 'row',1)

借鉴自:https://ww2.mathworks.cn/matlabcentral/answers/838473-how-to-center-column-names-in-table

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值