需要借助JAVA,代码示意如下:
import javax.swing.*;
%导入javax.swing类
table = findjobj(handles.uitable1);
%需要findjobj.m文件,matlab中是没有的
table1 = get(table,'Viewport');
jtable = get(table1,'View');
renderer = jtable.getCellRenderer(2,2);
renderer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
findjobj.m函数源码较多,见下载地址:
https://651696767.lanzous.com/iDvZtdzwhfc
附图: