我已经问这对Matlab Answers,但没有得到回应那里,所以我在这里尝试。右对齐值在应用程序设计
我有一些数字我想在UITable显示。由于我需要特定的值的格式(逗号后三位数,没有科学记数法),我将这些值转换为字符串。问题是这些字符串默认是左对齐的,看起来不太好。
当指南使用UITable,我能垫串与领先的空间,让他们正确就像下面
data = {'1532.000'; ' 5.543'; ' 26.457'};
使用单一空间字体,值显示这样的表对齐:
1532.000
5.543
26.457
目前我正在考虑切换到App Designer。我使用的是同样的空间填充字符串,但这里的可用性似乎将它们剥离。这是结果如下所示:
1532.000
5.543
26.457
有没有一种方法,使uitable
在应用程序设计保留空间,如它GUIDE做? 当然,它甚至会更好,直接右对齐的字符串,而不需要填充的,但据我所知,这是不可能的。
如果它的事项:我用Matlab R2016b。
编辑:
用于产生和填充UITable最小例子。这是一个简单的AppDesigner GUI,我只添加了一个表格和一个按钮(不修改任何属性)。该按钮的点击回调用于将数据添加到表格中。
classdef test < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
Button matlab.ui.control.Button
end
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
data = {'1532.000'; ' 5.543'; ' 26.457'};
app.UITable.Data = data;
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};
app.UITable.RowName = {};
app.UITable.Position = [127 180 302 185];
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [220 104 100 22];
end
end
methods (Access = public)
% Construct app
function app = test()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
按下按钮后,该表如下所示:
注意AppDesigner只允许我修改ButtonPushed
函数中的代码。
您是否尝试将[此解决方案]修改为适用于[此解决方案](http://stackoverflow.com/questions/38933254/how-to-customize-app-designer-figures-in-more-ways-than-officially-documented)您的需求?你所要求的几乎是相同的,唯一的区别是你询问一个表,并且链接的问题涉及一个列表......在任何情况下,请添加一些生成所讨论的uifigure的最小代码。 –
@ Dev-iL谢谢,看起来很有希望。我不确定我是否能够在本周花时间在这个星期,但一旦我有时间,我会做。我尝试时报告。 – luator
@ Dev-iL我发现时间比预期的要早。一个最小的例子被添加到问题中。我也尝试过你的尝试,但不幸的是,当我在浏览器中打开它时(所有其他元素都在那里),表似乎处理不同。 – luator